package com.esri.android.map;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import androidx.core.app.NotificationCompat;
import com.esri.android.map.LocationDisplayManager;
import com.esri.android.map.MapOptions;
import com.esri.android.map.MapSurface;
import com.esri.android.map.ags.ArcGISFeatureLayer;
import com.esri.android.map.ags.ArcGISTiledMapServiceLayer;
import com.esri.android.map.bing.BingMapsLayer;
import com.esri.android.map.c;
import com.esri.android.map.event.MapLoadAction;
import com.esri.android.map.event.OnBaseMapSwitchListener;
import com.esri.android.map.event.OnLongPressListener;
import com.esri.android.map.event.OnMapEventListener;
import com.esri.android.map.event.OnPanListener;
import com.esri.android.map.event.OnPinchListener;
import com.esri.android.map.event.OnSingleTapListener;
import com.esri.android.map.event.OnStatusChangedListener;
import com.esri.android.map.event.OnWebMapLoadListener;
import com.esri.android.map.event.OnZoomListener;
import com.esri.android.map.ogc.KMLLayer;
import com.esri.android.map.osm.OpenStreetMapLayer;
import com.esri.core.geometry.Envelope;
import com.esri.core.geometry.Geometry;
import com.esri.core.geometry.GeometryEngine;
import com.esri.core.geometry.Point;
import com.esri.core.geometry.Polygon;
import com.esri.core.geometry.SpatialReference;
import com.esri.core.internal.RuntimeHelper;
import com.esri.core.internal.tasks.e;
import com.esri.core.io.UserCredentials;
import com.esri.core.map.CallbackListener;
import com.esri.core.portal.BaseMap;
import com.esri.core.portal.Portal;
import com.esri.core.portal.WebMap;
import com.esri.core.portal.WebMapLayer;
import com.esri.core.symbol.Symbol;
import com.github.mikephil.charting.utils.Utils;
import com.tencent.smtt.sdk.TbsVideoCacheTask;
import java.io.File;
import java.io.InputStream;
import java.lang.ref.WeakReference;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.NumberFormat;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.Callable;
import java.util.concurrent.Future;
import org.codehaus.jackson.util.MinimalPrettyPrinter;

/* loaded from: classes.dex */
public class MapView extends ViewGroup implements ViewGroup.OnHierarchyChangeListener {
    private static final String H = "WebMap argument cannot be null.";
    private static final String I = "The MapView has to be initialized before switching the basemap.";
    private static final int J = 0;
    private static final int K = 1;
    private static final int L = -1;
    static NumberFormat h = NumberFormat.getInstance(Locale.ENGLISH);
    private boolean A;
    private float B;
    private float C;
    private int D;
    private volatile boolean E;
    private Grid F;
    private Future<Boolean> G;
    private float M;
    private float N;
    private double O;
    private boolean P;
    private MapAnimationListener Q;
    final MapSurface a;
    int b;
    int c;
    int d;
    int e;
    double f;
    Envelope g;
    LocationDisplayManager i;
    boolean j;
    Drawable k;
    Callout l;
    String m;
    a n;
    MapOptions o;
    boolean p;
    boolean q;
    boolean r;
    final transient Handler s;
    OnZoomListener t;
    OnPanListener u;
    OnLongPressListener v;
    OnPinchListener w;
    OnSingleTapListener x;
    OnStatusChangedListener y;
    private boolean z;

    private void a(float f, float f2, float f3) {
    }

    private void b(float f, float f2) {
    }

    @Override // android.view.ViewGroup.OnHierarchyChangeListener
    public void onChildViewRemoved(View view, View view2) {
    }

    private static final String a(Context context, TiledServiceLayer tiledServiceLayer, long j, int i) {
        if (context != null) {
            File a2 = RuntimeHelper.a(context);
            return new File(a2, "esritiles" + tiledServiceLayer.getUrlHashCode() + "." + j + "." + i + ".db").getAbsolutePath();
        }
        return null;
    }

    public MapView(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
        this.z = false;
        this.A = true;
        this.f = Utils.DOUBLE_EPSILON;
        this.g = null;
        this.j = false;
        this.l = null;
        this.D = -1;
        this.E = false;
        this.m = null;
        this.n = null;
        this.F = null;
        this.p = false;
        this.q = false;
        this.r = false;
        this.s = new Handler(new Handler.Callback() { // from class: com.esri.android.map.MapView.1
            {
                MapView.this = this;
            }

            @Override // android.os.Handler.Callback
            public boolean handleMessage(Message message) {
                if (MapView.this.isRecycled()) {
                    return false;
                }
                int i2 = message.getData().getInt(NotificationCompat.CATEGORY_STATUS);
                OnStatusChangedListener.STATUS fromInt = OnStatusChangedListener.STATUS.fromInt(i2);
                MapView mapView = MapView.this;
                int i3 = AnonymousClass9.a[fromInt.ordinal()];
                if (i3 == 1) {
                    MapView.this.b();
                    if (MapView.this.l != null && MapView.this.l.isShowing()) {
                        MapView.this.l.show();
                    }
                    if (MapView.this.j && MapView.this.i != null) {
                        MapView.this.i.start();
                    }
                    return b(i2, mapView);
                } else if (i3 != 2) {
                    if (i3 == 3) {
                        if (message.obj == mapView) {
                            MapView.this.a.e.compareAndSet(0, -1);
                            return b(i2, mapView);
                        } else {
                            Object obj = message.obj;
                            boolean a2 = a(i2, obj);
                            a((Layer) obj);
                            return a2;
                        }
                    }
                    if (i3 != 4) {
                        return false;
                    }
                    Object obj2 = message.obj;
                    boolean a3 = a(i2, obj2);
                    a((Layer) obj2);
                    return a3;
                } else {
                    Object obj3 = message.obj;
                    Layer layer = (Layer) obj3;
                    MapView.this.a(layer);
                    if (a(layer, 1)) {
                        MapView.this.b();
                        if (MapView.this.y != null) {
                            MapView.this.y.onStatusChanged(MapView.this, OnStatusChangedListener.STATUS.INITIALIZED);
                        }
                    }
                    if (MapView.this.o != null && (obj3 instanceof TiledServiceLayer)) {
                        TiledServiceLayer tiledServiceLayer = (TiledServiceLayer) obj3;
                        if (MapView.this.o.a == MapOptions.MapType.OSM) {
                            MapView.this.a(tiledServiceLayer);
                        } else {
                            for (String str : MapView.this.o.a.a()) {
                                if (tiledServiceLayer.getUrl().equals(str)) {
                                    MapView.this.a(tiledServiceLayer);
                                }
                            }
                        }
                    }
                    return b(i2, obj3);
                }
            }

            boolean a(int i2, Object obj) {
                if (MapView.this.y != null) {
                    MapView.this.y.onStatusChanged(obj, OnStatusChangedListener.STATUS.fromInt(i2));
                    return true;
                }
                return false;
            }

            boolean b(int i2, Object obj) {
                if (MapView.this.y != null) {
                    MapView.this.y.onStatusChanged(obj, OnStatusChangedListener.STATUS.fromInt(i2));
                    return true;
                }
                return false;
            }

            void a(Layer layer) {
                if (a(layer, -1) && MapView.this.y != null && MapView.this.a.e.get() == -1) {
                    MapView.this.y.onStatusChanged(MapView.this, OnStatusChangedListener.STATUS.INITIALIZATION_FAILED);
                }
            }

            private boolean a(Layer layer, int i2) {
                try {
                } catch (IndexOutOfBoundsException unused) {
                }
                synchronized (MapView.this.a.e) {
                    if (MapView.this.a.a.get(0).getID() != layer.getID() || MapView.this.a.e.get() == 1) {
                        return false;
                    }
                    if (i2 == 1) {
                        MapView.this.a.e.set(1);
                        return true;
                    }
                    return MapView.this.a.e.compareAndSet(0, -1);
                }
            }
        });
        this.t = null;
        this.u = null;
        this.v = null;
        this.w = null;
        this.x = null;
        this.y = null;
        this.P = false;
        this.Q = new MapAnimationListener() { // from class: com.esri.android.map.MapView.2
            {
                MapView.this = this;
            }

            @Override // com.esri.android.map.MapAnimationListener
            public void onAnimationFinished() {
                if (MapView.this.E || CalloutPopupWindow.a() > 0 || MapView.this.P) {
                    MapView.this.post(new Runnable() { // from class: com.esri.android.map.MapView.2.1
                        {
                            AnonymousClass2.this = this;
                        }

                        @Override // java.lang.Runnable
                        public void run() {
                            if (CalloutPopupWindow.a() > 0) {
                                CalloutPopupWindow.a(MapView.this);
                            }
                            if (MapView.this.E) {
                                MapView.this.l.a();
                                MapView.this.E = false;
                            }
                            if (MapView.this.P) {
                                MapView.this.P = false;
                                MapView.this.t.postAction(MapView.this.M, MapView.this.N, MapView.this.O);
                            }
                        }
                    });
                }
            }

            @Override // com.esri.android.map.MapAnimationListener
            public void onAnimating(boolean z) {
                if (z) {
                    MapView.this.e();
                }
            }
        };
        MapSurface a2 = a(context);
        this.a = a2;
        this.F = new Grid(a2);
        a(context, attributeSet);
    }

    private MapSurface a(Context context) {
        if (isInEditMode()) {
            return null;
        }
        MapSurface mapSurface = new MapSurface(context, this.s);
        mapSurface.a(this.Q);
        addView(mapSurface);
        mapSurface.j = new MapSurface.SizeChangedListener() { // from class: com.esri.android.map.MapView.3
            {
                MapView.this = this;
            }

            @Override // com.esri.android.map.MapSurface.SizeChangedListener
            public void onMapSurfaceSizeChanged() {
                CalloutPopupWindow.a(MapView.this);
                if (MapView.this.l == null || !MapView.this.l.isShowing()) {
                    return;
                }
                MapView.this.l.show();
            }
        };
        return mapSurface;
    }

    public MapView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        this.z = false;
        this.A = true;
        this.f = Utils.DOUBLE_EPSILON;
        this.g = null;
        this.j = false;
        this.l = null;
        this.D = -1;
        this.E = false;
        this.m = null;
        this.n = null;
        this.F = null;
        this.p = false;
        this.q = false;
        this.r = false;
        this.s = new Handler(new Handler.Callback() { // from class: com.esri.android.map.MapView.1
            {
                MapView.this = this;
            }

            @Override // android.os.Handler.Callback
            public boolean handleMessage(Message message) {
                if (MapView.this.isRecycled()) {
                    return false;
                }
                int i2 = message.getData().getInt(NotificationCompat.CATEGORY_STATUS);
                OnStatusChangedListener.STATUS fromInt = OnStatusChangedListener.STATUS.fromInt(i2);
                MapView mapView = MapView.this;
                int i3 = AnonymousClass9.a[fromInt.ordinal()];
                if (i3 == 1) {
                    MapView.this.b();
                    if (MapView.this.l != null && MapView.this.l.isShowing()) {
                        MapView.this.l.show();
                    }
                    if (MapView.this.j && MapView.this.i != null) {
                        MapView.this.i.start();
                    }
                    return b(i2, mapView);
                } else if (i3 != 2) {
                    if (i3 == 3) {
                        if (message.obj == mapView) {
                            MapView.this.a.e.compareAndSet(0, -1);
                            return b(i2, mapView);
                        } else {
                            Object obj = message.obj;
                            boolean a2 = a(i2, obj);
                            a((Layer) obj);
                            return a2;
                        }
                    }
                    if (i3 != 4) {
                        return false;
                    }
                    Object obj2 = message.obj;
                    boolean a3 = a(i2, obj2);
                    a((Layer) obj2);
                    return a3;
                } else {
                    Object obj3 = message.obj;
                    Layer layer = (Layer) obj3;
                    MapView.this.a(layer);
                    if (a(layer, 1)) {
                        MapView.this.b();
                        if (MapView.this.y != null) {
                            MapView.this.y.onStatusChanged(MapView.this, OnStatusChangedListener.STATUS.INITIALIZED);
                        }
                    }
                    if (MapView.this.o != null && (obj3 instanceof TiledServiceLayer)) {
                        TiledServiceLayer tiledServiceLayer = (TiledServiceLayer) obj3;
                        if (MapView.this.o.a == MapOptions.MapType.OSM) {
                            MapView.this.a(tiledServiceLayer);
                        } else {
                            for (String str : MapView.this.o.a.a()) {
                                if (tiledServiceLayer.getUrl().equals(str)) {
                                    MapView.this.a(tiledServiceLayer);
                                }
                            }
                        }
                    }
                    return b(i2, obj3);
                }
            }

            boolean a(int i2, Object obj) {
                if (MapView.this.y != null) {
                    MapView.this.y.onStatusChanged(obj, OnStatusChangedListener.STATUS.fromInt(i2));
                    return true;
                }
                return false;
            }

            boolean b(int i2, Object obj) {
                if (MapView.this.y != null) {
                    MapView.this.y.onStatusChanged(obj, OnStatusChangedListener.STATUS.fromInt(i2));
                    return true;
                }
                return false;
            }

            void a(Layer layer) {
                if (a(layer, -1) && MapView.this.y != null && MapView.this.a.e.get() == -1) {
                    MapView.this.y.onStatusChanged(MapView.this, OnStatusChangedListener.STATUS.INITIALIZATION_FAILED);
                }
            }

            private boolean a(Layer layer, int i2) {
                try {
                } catch (IndexOutOfBoundsException unused) {
                }
                synchronized (MapView.this.a.e) {
                    if (MapView.this.a.a.get(0).getID() != layer.getID() || MapView.this.a.e.get() == 1) {
                        return false;
                    }
                    if (i2 == 1) {
                        MapView.this.a.e.set(1);
                        return true;
                    }
                    return MapView.this.a.e.compareAndSet(0, -1);
                }
            }
        });
        this.t = null;
        this.u = null;
        this.v = null;
        this.w = null;
        this.x = null;
        this.y = null;
        this.P = false;
        this.Q = new MapAnimationListener() { // from class: com.esri.android.map.MapView.2
            {
                MapView.this = this;
            }

            @Override // com.esri.android.map.MapAnimationListener
            public void onAnimationFinished() {
                if (MapView.this.E || CalloutPopupWindow.a() > 0 || MapView.this.P) {
                    MapView.this.post(new Runnable() { // from class: com.esri.android.map.MapView.2.1
                        {
                            AnonymousClass2.this = this;
                        }

                        @Override // java.lang.Runnable
                        public void run() {
                            if (CalloutPopupWindow.a() > 0) {
                                CalloutPopupWindow.a(MapView.this);
                            }
                            if (MapView.this.E) {
                                MapView.this.l.a();
                                MapView.this.E = false;
                            }
                            if (MapView.this.P) {
                                MapView.this.P = false;
                                MapView.this.t.postAction(MapView.this.M, MapView.this.N, MapView.this.O);
                            }
                        }
                    });
                }
            }

            @Override // com.esri.android.map.MapAnimationListener
            public void onAnimating(boolean z) {
                if (z) {
                    MapView.this.e();
                }
            }
        };
        MapSurface a2 = a(context);
        this.a = a2;
        this.F = new Grid(a2);
        a(context, attributeSet);
    }

    public MapView(Context context) {
        super(context);
        this.z = false;
        this.A = true;
        this.f = Utils.DOUBLE_EPSILON;
        this.g = null;
        this.j = false;
        this.l = null;
        this.D = -1;
        this.E = false;
        this.m = null;
        this.n = null;
        this.F = null;
        this.p = false;
        this.q = false;
        this.r = false;
        this.s = new Handler(new Handler.Callback() { // from class: com.esri.android.map.MapView.1
            {
                MapView.this = this;
            }

            @Override // android.os.Handler.Callback
            public boolean handleMessage(Message message) {
                if (MapView.this.isRecycled()) {
                    return false;
                }
                int i2 = message.getData().getInt(NotificationCompat.CATEGORY_STATUS);
                OnStatusChangedListener.STATUS fromInt = OnStatusChangedListener.STATUS.fromInt(i2);
                MapView mapView = MapView.this;
                int i3 = AnonymousClass9.a[fromInt.ordinal()];
                if (i3 == 1) {
                    MapView.this.b();
                    if (MapView.this.l != null && MapView.this.l.isShowing()) {
                        MapView.this.l.show();
                    }
                    if (MapView.this.j && MapView.this.i != null) {
                        MapView.this.i.start();
                    }
                    return b(i2, mapView);
                } else if (i3 != 2) {
                    if (i3 == 3) {
                        if (message.obj == mapView) {
                            MapView.this.a.e.compareAndSet(0, -1);
                            return b(i2, mapView);
                        } else {
                            Object obj = message.obj;
                            boolean a2 = a(i2, obj);
                            a((Layer) obj);
                            return a2;
                        }
                    }
                    if (i3 != 4) {
                        return false;
                    }
                    Object obj2 = message.obj;
                    boolean a3 = a(i2, obj2);
                    a((Layer) obj2);
                    return a3;
                } else {
                    Object obj3 = message.obj;
                    Layer layer = (Layer) obj3;
                    MapView.this.a(layer);
                    if (a(layer, 1)) {
                        MapView.this.b();
                        if (MapView.this.y != null) {
                            MapView.this.y.onStatusChanged(MapView.this, OnStatusChangedListener.STATUS.INITIALIZED);
                        }
                    }
                    if (MapView.this.o != null && (obj3 instanceof TiledServiceLayer)) {
                        TiledServiceLayer tiledServiceLayer = (TiledServiceLayer) obj3;
                        if (MapView.this.o.a == MapOptions.MapType.OSM) {
                            MapView.this.a(tiledServiceLayer);
                        } else {
                            for (String str : MapView.this.o.a.a()) {
                                if (tiledServiceLayer.getUrl().equals(str)) {
                                    MapView.this.a(tiledServiceLayer);
                                }
                            }
                        }
                    }
                    return b(i2, obj3);
                }
            }

            boolean a(int i2, Object obj) {
                if (MapView.this.y != null) {
                    MapView.this.y.onStatusChanged(obj, OnStatusChangedListener.STATUS.fromInt(i2));
                    return true;
                }
                return false;
            }

            boolean b(int i2, Object obj) {
                if (MapView.this.y != null) {
                    MapView.this.y.onStatusChanged(obj, OnStatusChangedListener.STATUS.fromInt(i2));
                    return true;
                }
                return false;
            }

            void a(Layer layer) {
                if (a(layer, -1) && MapView.this.y != null && MapView.this.a.e.get() == -1) {
                    MapView.this.y.onStatusChanged(MapView.this, OnStatusChangedListener.STATUS.INITIALIZATION_FAILED);
                }
            }

            private boolean a(Layer layer, int i2) {
                try {
                } catch (IndexOutOfBoundsException unused) {
                }
                synchronized (MapView.this.a.e) {
                    if (MapView.this.a.a.get(0).getID() != layer.getID() || MapView.this.a.e.get() == 1) {
                        return false;
                    }
                    if (i2 == 1) {
                        MapView.this.a.e.set(1);
                        return true;
                    }
                    return MapView.this.a.e.compareAndSet(0, -1);
                }
            }
        });
        this.t = null;
        this.u = null;
        this.v = null;
        this.w = null;
        this.x = null;
        this.y = null;
        this.P = false;
        this.Q = new MapAnimationListener() { // from class: com.esri.android.map.MapView.2
            {
                MapView.this = this;
            }

            @Override // com.esri.android.map.MapAnimationListener
            public void onAnimationFinished() {
                if (MapView.this.E || CalloutPopupWindow.a() > 0 || MapView.this.P) {
                    MapView.this.post(new Runnable() { // from class: com.esri.android.map.MapView.2.1
                        {
                            AnonymousClass2.this = this;
                        }

                        @Override // java.lang.Runnable
                        public void run() {
                            if (CalloutPopupWindow.a() > 0) {
                                CalloutPopupWindow.a(MapView.this);
                            }
                            if (MapView.this.E) {
                                MapView.this.l.a();
                                MapView.this.E = false;
                            }
                            if (MapView.this.P) {
                                MapView.this.P = false;
                                MapView.this.t.postAction(MapView.this.M, MapView.this.N, MapView.this.O);
                            }
                        }
                    });
                }
            }

            @Override // com.esri.android.map.MapAnimationListener
            public void onAnimating(boolean z) {
                if (z) {
                    MapView.this.e();
                }
            }
        };
        MapSurface a2 = a(context);
        this.a = a2;
        this.F = new Grid(a2);
        a(context, (AttributeSet) null);
    }

    public MapView(Context context, SpatialReference spatialReference, Envelope envelope) {
        super(context);
        this.z = false;
        this.A = true;
        this.f = Utils.DOUBLE_EPSILON;
        this.g = null;
        this.j = false;
        this.l = null;
        this.D = -1;
        this.E = false;
        this.m = null;
        this.n = null;
        this.F = null;
        this.p = false;
        this.q = false;
        this.r = false;
        this.s = new Handler(new Handler.Callback() { // from class: com.esri.android.map.MapView.1
            {
                MapView.this = this;
            }

            @Override // android.os.Handler.Callback
            public boolean handleMessage(Message message) {
                if (MapView.this.isRecycled()) {
                    return false;
                }
                int i2 = message.getData().getInt(NotificationCompat.CATEGORY_STATUS);
                OnStatusChangedListener.STATUS fromInt = OnStatusChangedListener.STATUS.fromInt(i2);
                MapView mapView = MapView.this;
                int i3 = AnonymousClass9.a[fromInt.ordinal()];
                if (i3 == 1) {
                    MapView.this.b();
                    if (MapView.this.l != null && MapView.this.l.isShowing()) {
                        MapView.this.l.show();
                    }
                    if (MapView.this.j && MapView.this.i != null) {
                        MapView.this.i.start();
                    }
                    return b(i2, mapView);
                } else if (i3 != 2) {
                    if (i3 == 3) {
                        if (message.obj == mapView) {
                            MapView.this.a.e.compareAndSet(0, -1);
                            return b(i2, mapView);
                        } else {
                            Object obj = message.obj;
                            boolean a2 = a(i2, obj);
                            a((Layer) obj);
                            return a2;
                        }
                    }
                    if (i3 != 4) {
                        return false;
                    }
                    Object obj2 = message.obj;
                    boolean a3 = a(i2, obj2);
                    a((Layer) obj2);
                    return a3;
                } else {
                    Object obj3 = message.obj;
                    Layer layer = (Layer) obj3;
                    MapView.this.a(layer);
                    if (a(layer, 1)) {
                        MapView.this.b();
                        if (MapView.this.y != null) {
                            MapView.this.y.onStatusChanged(MapView.this, OnStatusChangedListener.STATUS.INITIALIZED);
                        }
                    }
                    if (MapView.this.o != null && (obj3 instanceof TiledServiceLayer)) {
                        TiledServiceLayer tiledServiceLayer = (TiledServiceLayer) obj3;
                        if (MapView.this.o.a == MapOptions.MapType.OSM) {
                            MapView.this.a(tiledServiceLayer);
                        } else {
                            for (String str : MapView.this.o.a.a()) {
                                if (tiledServiceLayer.getUrl().equals(str)) {
                                    MapView.this.a(tiledServiceLayer);
                                }
                            }
                        }
                    }
                    return b(i2, obj3);
                }
            }

            boolean a(int i2, Object obj) {
                if (MapView.this.y != null) {
                    MapView.this.y.onStatusChanged(obj, OnStatusChangedListener.STATUS.fromInt(i2));
                    return true;
                }
                return false;
            }

            boolean b(int i2, Object obj) {
                if (MapView.this.y != null) {
                    MapView.this.y.onStatusChanged(obj, OnStatusChangedListener.STATUS.fromInt(i2));
                    return true;
                }
                return false;
            }

            void a(Layer layer) {
                if (a(layer, -1) && MapView.this.y != null && MapView.this.a.e.get() == -1) {
                    MapView.this.y.onStatusChanged(MapView.this, OnStatusChangedListener.STATUS.INITIALIZATION_FAILED);
                }
            }

            private boolean a(Layer layer, int i2) {
                try {
                } catch (IndexOutOfBoundsException unused) {
                }
                synchronized (MapView.this.a.e) {
                    if (MapView.this.a.a.get(0).getID() != layer.getID() || MapView.this.a.e.get() == 1) {
                        return false;
                    }
                    if (i2 == 1) {
                        MapView.this.a.e.set(1);
                        return true;
                    }
                    return MapView.this.a.e.compareAndSet(0, -1);
                }
            }
        });
        this.t = null;
        this.u = null;
        this.v = null;
        this.w = null;
        this.x = null;
        this.y = null;
        this.P = false;
        this.Q = new MapAnimationListener() { // from class: com.esri.android.map.MapView.2
            {
                MapView.this = this;
            }

            @Override // com.esri.android.map.MapAnimationListener
            public void onAnimationFinished() {
                if (MapView.this.E || CalloutPopupWindow.a() > 0 || MapView.this.P) {
                    MapView.this.post(new Runnable() { // from class: com.esri.android.map.MapView.2.1
                        {
                            AnonymousClass2.this = this;
                        }

                        @Override // java.lang.Runnable
                        public void run() {
                            if (CalloutPopupWindow.a() > 0) {
                                CalloutPopupWindow.a(MapView.this);
                            }
                            if (MapView.this.E) {
                                MapView.this.l.a();
                                MapView.this.E = false;
                            }
                            if (MapView.this.P) {
                                MapView.this.P = false;
                                MapView.this.t.postAction(MapView.this.M, MapView.this.N, MapView.this.O);
                            }
                        }
                    });
                }
            }

            @Override // com.esri.android.map.MapAnimationListener
            public void onAnimating(boolean z) {
                if (z) {
                    MapView.this.e();
                }
            }
        };
        MapSurface a2 = a(context);
        this.a = a2;
        this.F = new Grid(a2);
        a(context, (AttributeSet) null);
        a(spatialReference, envelope);
    }

    public MapView(Context context, String str, String str2, String str3) {
        this(context, str, str2, str3, (String) null, (OnMapEventListener) null);
    }

    public MapView(Context context, String str, String str2, String str3, String str4) {
        this(context, str, str2, str3, str4, (OnMapEventListener) null);
    }

    public MapView(Context context, String str, String str2, String str3, String str4, OnMapEventListener onMapEventListener) {
        super(context);
        this.z = false;
        this.A = true;
        this.f = Utils.DOUBLE_EPSILON;
        this.g = null;
        this.j = false;
        this.l = null;
        this.D = -1;
        this.E = false;
        this.m = null;
        this.n = null;
        this.F = null;
        this.p = false;
        this.q = false;
        this.r = false;
        this.s = new Handler(new Handler.Callback() { // from class: com.esri.android.map.MapView.1
            {
                MapView.this = this;
            }

            @Override // android.os.Handler.Callback
            public boolean handleMessage(Message message) {
                if (MapView.this.isRecycled()) {
                    return false;
                }
                int i2 = message.getData().getInt(NotificationCompat.CATEGORY_STATUS);
                OnStatusChangedListener.STATUS fromInt = OnStatusChangedListener.STATUS.fromInt(i2);
                MapView mapView = MapView.this;
                int i3 = AnonymousClass9.a[fromInt.ordinal()];
                if (i3 == 1) {
                    MapView.this.b();
                    if (MapView.this.l != null && MapView.this.l.isShowing()) {
                        MapView.this.l.show();
                    }
                    if (MapView.this.j && MapView.this.i != null) {
                        MapView.this.i.start();
                    }
                    return b(i2, mapView);
                } else if (i3 != 2) {
                    if (i3 == 3) {
                        if (message.obj == mapView) {
                            MapView.this.a.e.compareAndSet(0, -1);
                            return b(i2, mapView);
                        } else {
                            Object obj = message.obj;
                            boolean a2 = a(i2, obj);
                            a((Layer) obj);
                            return a2;
                        }
                    }
                    if (i3 != 4) {
                        return false;
                    }
                    Object obj2 = message.obj;
                    boolean a3 = a(i2, obj2);
                    a((Layer) obj2);
                    return a3;
                } else {
                    Object obj3 = message.obj;
                    Layer layer = (Layer) obj3;
                    MapView.this.a(layer);
                    if (a(layer, 1)) {
                        MapView.this.b();
                        if (MapView.this.y != null) {
                            MapView.this.y.onStatusChanged(MapView.this, OnStatusChangedListener.STATUS.INITIALIZED);
                        }
                    }
                    if (MapView.this.o != null && (obj3 instanceof TiledServiceLayer)) {
                        TiledServiceLayer tiledServiceLayer = (TiledServiceLayer) obj3;
                        if (MapView.this.o.a == MapOptions.MapType.OSM) {
                            MapView.this.a(tiledServiceLayer);
                        } else {
                            for (String str5 : MapView.this.o.a.a()) {
                                if (tiledServiceLayer.getUrl().equals(str5)) {
                                    MapView.this.a(tiledServiceLayer);
                                }
                            }
                        }
                    }
                    return b(i2, obj3);
                }
            }

            boolean a(int i2, Object obj) {
                if (MapView.this.y != null) {
                    MapView.this.y.onStatusChanged(obj, OnStatusChangedListener.STATUS.fromInt(i2));
                    return true;
                }
                return false;
            }

            boolean b(int i2, Object obj) {
                if (MapView.this.y != null) {
                    MapView.this.y.onStatusChanged(obj, OnStatusChangedListener.STATUS.fromInt(i2));
                    return true;
                }
                return false;
            }

            void a(Layer layer) {
                if (a(layer, -1) && MapView.this.y != null && MapView.this.a.e.get() == -1) {
                    MapView.this.y.onStatusChanged(MapView.this, OnStatusChangedListener.STATUS.INITIALIZATION_FAILED);
                }
            }

            private boolean a(Layer layer, int i2) {
                try {
                } catch (IndexOutOfBoundsException unused) {
                }
                synchronized (MapView.this.a.e) {
                    if (MapView.this.a.a.get(0).getID() != layer.getID() || MapView.this.a.e.get() == 1) {
                        return false;
                    }
                    if (i2 == 1) {
                        MapView.this.a.e.set(1);
                        return true;
                    }
                    return MapView.this.a.e.compareAndSet(0, -1);
                }
            }
        });
        this.t = null;
        this.u = null;
        this.v = null;
        this.w = null;
        this.x = null;
        this.y = null;
        this.P = false;
        this.Q = new MapAnimationListener() { // from class: com.esri.android.map.MapView.2
            {
                MapView.this = this;
            }

            @Override // com.esri.android.map.MapAnimationListener
            public void onAnimationFinished() {
                if (MapView.this.E || CalloutPopupWindow.a() > 0 || MapView.this.P) {
                    MapView.this.post(new Runnable() { // from class: com.esri.android.map.MapView.2.1
                        {
                            AnonymousClass2.this = this;
                        }

                        @Override // java.lang.Runnable
                        public void run() {
                            if (CalloutPopupWindow.a() > 0) {
                                CalloutPopupWindow.a(MapView.this);
                            }
                            if (MapView.this.E) {
                                MapView.this.l.a();
                                MapView.this.E = false;
                            }
                            if (MapView.this.P) {
                                MapView.this.P = false;
                                MapView.this.t.postAction(MapView.this.M, MapView.this.N, MapView.this.O);
                            }
                        }
                    });
                }
            }

            @Override // com.esri.android.map.MapAnimationListener
            public void onAnimating(boolean z) {
                if (z) {
                    MapView.this.e();
                }
            }
        };
        MapSurface a2 = a(context);
        this.a = a2;
        this.F = new Grid(a2);
        a(context, (AttributeSet) null);
        this.m = str4;
        a(a(str2, str3), (c.a) null, (c.a) str, onMapEventListener);
    }

    public MapView(Context context, String str, UserCredentials userCredentials, String str2, OnMapEventListener onMapEventListener) {
        super(context);
        this.z = false;
        this.A = true;
        this.f = Utils.DOUBLE_EPSILON;
        this.g = null;
        this.j = false;
        this.l = null;
        this.D = -1;
        this.E = false;
        this.m = null;
        this.n = null;
        this.F = null;
        this.p = false;
        this.q = false;
        this.r = false;
        this.s = new Handler(new Handler.Callback() { // from class: com.esri.android.map.MapView.1
            {
                MapView.this = this;
            }

            @Override // android.os.Handler.Callback
            public boolean handleMessage(Message message) {
                if (MapView.this.isRecycled()) {
                    return false;
                }
                int i2 = message.getData().getInt(NotificationCompat.CATEGORY_STATUS);
                OnStatusChangedListener.STATUS fromInt = OnStatusChangedListener.STATUS.fromInt(i2);
                MapView mapView = MapView.this;
                int i3 = AnonymousClass9.a[fromInt.ordinal()];
                if (i3 == 1) {
                    MapView.this.b();
                    if (MapView.this.l != null && MapView.this.l.isShowing()) {
                        MapView.this.l.show();
                    }
                    if (MapView.this.j && MapView.this.i != null) {
                        MapView.this.i.start();
                    }
                    return b(i2, mapView);
                } else if (i3 != 2) {
                    if (i3 == 3) {
                        if (message.obj == mapView) {
                            MapView.this.a.e.compareAndSet(0, -1);
                            return b(i2, mapView);
                        } else {
                            Object obj = message.obj;
                            boolean a2 = a(i2, obj);
                            a((Layer) obj);
                            return a2;
                        }
                    }
                    if (i3 != 4) {
                        return false;
                    }
                    Object obj2 = message.obj;
                    boolean a3 = a(i2, obj2);
                    a((Layer) obj2);
                    return a3;
                } else {
                    Object obj3 = message.obj;
                    Layer layer = (Layer) obj3;
                    MapView.this.a(layer);
                    if (a(layer, 1)) {
                        MapView.this.b();
                        if (MapView.this.y != null) {
                            MapView.this.y.onStatusChanged(MapView.this, OnStatusChangedListener.STATUS.INITIALIZED);
                        }
                    }
                    if (MapView.this.o != null && (obj3 instanceof TiledServiceLayer)) {
                        TiledServiceLayer tiledServiceLayer = (TiledServiceLayer) obj3;
                        if (MapView.this.o.a == MapOptions.MapType.OSM) {
                            MapView.this.a(tiledServiceLayer);
                        } else {
                            for (String str5 : MapView.this.o.a.a()) {
                                if (tiledServiceLayer.getUrl().equals(str5)) {
                                    MapView.this.a(tiledServiceLayer);
                                }
                            }
                        }
                    }
                    return b(i2, obj3);
                }
            }

            boolean a(int i2, Object obj) {
                if (MapView.this.y != null) {
                    MapView.this.y.onStatusChanged(obj, OnStatusChangedListener.STATUS.fromInt(i2));
                    return true;
                }
                return false;
            }

            boolean b(int i2, Object obj) {
                if (MapView.this.y != null) {
                    MapView.this.y.onStatusChanged(obj, OnStatusChangedListener.STATUS.fromInt(i2));
                    return true;
                }
                return false;
            }

            void a(Layer layer) {
                if (a(layer, -1) && MapView.this.y != null && MapView.this.a.e.get() == -1) {
                    MapView.this.y.onStatusChanged(MapView.this, OnStatusChangedListener.STATUS.INITIALIZATION_FAILED);
                }
            }

            private boolean a(Layer layer, int i2) {
                try {
                } catch (IndexOutOfBoundsException unused) {
                }
                synchronized (MapView.this.a.e) {
                    if (MapView.this.a.a.get(0).getID() != layer.getID() || MapView.this.a.e.get() == 1) {
                        return false;
                    }
                    if (i2 == 1) {
                        MapView.this.a.e.set(1);
                        return true;
                    }
                    return MapView.this.a.e.compareAndSet(0, -1);
                }
            }
        });
        this.t = null;
        this.u = null;
        this.v = null;
        this.w = null;
        this.x = null;
        this.y = null;
        this.P = false;
        this.Q = new MapAnimationListener() { // from class: com.esri.android.map.MapView.2
            {
                MapView.this = this;
            }

            @Override // com.esri.android.map.MapAnimationListener
            public void onAnimationFinished() {
                if (MapView.this.E || CalloutPopupWindow.a() > 0 || MapView.this.P) {
                    MapView.this.post(new Runnable() { // from class: com.esri.android.map.MapView.2.1
                        {
                            AnonymousClass2.this = this;
                        }

                        @Override // java.lang.Runnable
                        public void run() {
                            if (CalloutPopupWindow.a() > 0) {
                                CalloutPopupWindow.a(MapView.this);
                            }
                            if (MapView.this.E) {
                                MapView.this.l.a();
                                MapView.this.E = false;
                            }
                            if (MapView.this.P) {
                                MapView.this.P = false;
                                MapView.this.t.postAction(MapView.this.M, MapView.this.N, MapView.this.O);
                            }
                        }
                    });
                }
            }

            @Override // com.esri.android.map.MapAnimationListener
            public void onAnimating(boolean z) {
                if (z) {
                    MapView.this.e();
                }
            }
        };
        MapSurface a2 = a(context);
        this.a = a2;
        this.F = new Grid(a2);
        a(context, (AttributeSet) null);
        this.m = str2;
        a(userCredentials, (c.a) null, (c.a) str, onMapEventListener);
    }

    public MapView(Context context, WebMap webMap, String str, OnMapEventListener onMapEventListener) {
        super(context);
        this.z = false;
        this.A = true;
        this.f = Utils.DOUBLE_EPSILON;
        this.g = null;
        this.j = false;
        this.l = null;
        this.D = -1;
        this.E = false;
        this.m = null;
        this.n = null;
        this.F = null;
        this.p = false;
        this.q = false;
        this.r = false;
        this.s = new Handler(new Handler.Callback() { // from class: com.esri.android.map.MapView.1
            {
                MapView.this = this;
            }

            @Override // android.os.Handler.Callback
            public boolean handleMessage(Message message) {
                if (MapView.this.isRecycled()) {
                    return false;
                }
                int i2 = message.getData().getInt(NotificationCompat.CATEGORY_STATUS);
                OnStatusChangedListener.STATUS fromInt = OnStatusChangedListener.STATUS.fromInt(i2);
                MapView mapView = MapView.this;
                int i3 = AnonymousClass9.a[fromInt.ordinal()];
                if (i3 == 1) {
                    MapView.this.b();
                    if (MapView.this.l != null && MapView.this.l.isShowing()) {
                        MapView.this.l.show();
                    }
                    if (MapView.this.j && MapView.this.i != null) {
                        MapView.this.i.start();
                    }
                    return b(i2, mapView);
                } else if (i3 != 2) {
                    if (i3 == 3) {
                        if (message.obj == mapView) {
                            MapView.this.a.e.compareAndSet(0, -1);
                            return b(i2, mapView);
                        } else {
                            Object obj = message.obj;
                            boolean a2 = a(i2, obj);
                            a((Layer) obj);
                            return a2;
                        }
                    }
                    if (i3 != 4) {
                        return false;
                    }
                    Object obj2 = message.obj;
                    boolean a3 = a(i2, obj2);
                    a((Layer) obj2);
                    return a3;
                } else {
                    Object obj3 = message.obj;
                    Layer layer = (Layer) obj3;
                    MapView.this.a(layer);
                    if (a(layer, 1)) {
                        MapView.this.b();
                        if (MapView.this.y != null) {
                            MapView.this.y.onStatusChanged(MapView.this, OnStatusChangedListener.STATUS.INITIALIZED);
                        }
                    }
                    if (MapView.this.o != null && (obj3 instanceof TiledServiceLayer)) {
                        TiledServiceLayer tiledServiceLayer = (TiledServiceLayer) obj3;
                        if (MapView.this.o.a == MapOptions.MapType.OSM) {
                            MapView.this.a(tiledServiceLayer);
                        } else {
                            for (String str5 : MapView.this.o.a.a()) {
                                if (tiledServiceLayer.getUrl().equals(str5)) {
                                    MapView.this.a(tiledServiceLayer);
                                }
                            }
                        }
                    }
                    return b(i2, obj3);
                }
            }

            boolean a(int i2, Object obj) {
                if (MapView.this.y != null) {
                    MapView.this.y.onStatusChanged(obj, OnStatusChangedListener.STATUS.fromInt(i2));
                    return true;
                }
                return false;
            }

            boolean b(int i2, Object obj) {
                if (MapView.this.y != null) {
                    MapView.this.y.onStatusChanged(obj, OnStatusChangedListener.STATUS.fromInt(i2));
                    return true;
                }
                return false;
            }

            void a(Layer layer) {
                if (a(layer, -1) && MapView.this.y != null && MapView.this.a.e.get() == -1) {
                    MapView.this.y.onStatusChanged(MapView.this, OnStatusChangedListener.STATUS.INITIALIZATION_FAILED);
                }
            }

            private boolean a(Layer layer, int i2) {
                try {
                } catch (IndexOutOfBoundsException unused) {
                }
                synchronized (MapView.this.a.e) {
                    if (MapView.this.a.a.get(0).getID() != layer.getID() || MapView.this.a.e.get() == 1) {
                        return false;
                    }
                    if (i2 == 1) {
                        MapView.this.a.e.set(1);
                        return true;
                    }
                    return MapView.this.a.e.compareAndSet(0, -1);
                }
            }
        });
        this.t = null;
        this.u = null;
        this.v = null;
        this.w = null;
        this.x = null;
        this.y = null;
        this.P = false;
        this.Q = new MapAnimationListener() { // from class: com.esri.android.map.MapView.2
            {
                MapView.this = this;
            }

            @Override // com.esri.android.map.MapAnimationListener
            public void onAnimationFinished() {
                if (MapView.this.E || CalloutPopupWindow.a() > 0 || MapView.this.P) {
                    MapView.this.post(new Runnable() { // from class: com.esri.android.map.MapView.2.1
                        {
                            AnonymousClass2.this = this;
                        }

                        @Override // java.lang.Runnable
                        public void run() {
                            if (CalloutPopupWindow.a() > 0) {
                                CalloutPopupWindow.a(MapView.this);
                            }
                            if (MapView.this.E) {
                                MapView.this.l.a();
                                MapView.this.E = false;
                            }
                            if (MapView.this.P) {
                                MapView.this.P = false;
                                MapView.this.t.postAction(MapView.this.M, MapView.this.N, MapView.this.O);
                            }
                        }
                    });
                }
            }

            @Override // com.esri.android.map.MapAnimationListener
            public void onAnimating(boolean z) {
                if (z) {
                    MapView.this.e();
                }
            }
        };
        MapSurface a2 = a(context);
        this.a = a2;
        this.F = new Grid(a2);
        a(context, (AttributeSet) null);
        this.m = str;
        a(webMap);
        a((UserCredentials) null, (c.a) null, (c.a) webMap, onMapEventListener);
    }

    public MapView(Context context, WebMap webMap, BaseMap baseMap, String str, OnMapEventListener onMapEventListener) {
        super(context);
        this.z = false;
        this.A = true;
        this.f = Utils.DOUBLE_EPSILON;
        this.g = null;
        this.j = false;
        this.l = null;
        this.D = -1;
        this.E = false;
        this.m = null;
        this.n = null;
        this.F = null;
        this.p = false;
        this.q = false;
        this.r = false;
        this.s = new Handler(new Handler.Callback() { // from class: com.esri.android.map.MapView.1
            {
                MapView.this = this;
            }

            @Override // android.os.Handler.Callback
            public boolean handleMessage(Message message) {
                if (MapView.this.isRecycled()) {
                    return false;
                }
                int i2 = message.getData().getInt(NotificationCompat.CATEGORY_STATUS);
                OnStatusChangedListener.STATUS fromInt = OnStatusChangedListener.STATUS.fromInt(i2);
                MapView mapView = MapView.this;
                int i3 = AnonymousClass9.a[fromInt.ordinal()];
                if (i3 == 1) {
                    MapView.this.b();
                    if (MapView.this.l != null && MapView.this.l.isShowing()) {
                        MapView.this.l.show();
                    }
                    if (MapView.this.j && MapView.this.i != null) {
                        MapView.this.i.start();
                    }
                    return b(i2, mapView);
                } else if (i3 != 2) {
                    if (i3 == 3) {
                        if (message.obj == mapView) {
                            MapView.this.a.e.compareAndSet(0, -1);
                            return b(i2, mapView);
                        } else {
                            Object obj = message.obj;
                            boolean a2 = a(i2, obj);
                            a((Layer) obj);
                            return a2;
                        }
                    }
                    if (i3 != 4) {
                        return false;
                    }
                    Object obj2 = message.obj;
                    boolean a3 = a(i2, obj2);
                    a((Layer) obj2);
                    return a3;
                } else {
                    Object obj3 = message.obj;
                    Layer layer = (Layer) obj3;
                    MapView.this.a(layer);
                    if (a(layer, 1)) {
                        MapView.this.b();
                        if (MapView.this.y != null) {
                            MapView.this.y.onStatusChanged(MapView.this, OnStatusChangedListener.STATUS.INITIALIZED);
                        }
                    }
                    if (MapView.this.o != null && (obj3 instanceof TiledServiceLayer)) {
                        TiledServiceLayer tiledServiceLayer = (TiledServiceLayer) obj3;
                        if (MapView.this.o.a == MapOptions.MapType.OSM) {
                            MapView.this.a(tiledServiceLayer);
                        } else {
                            for (String str5 : MapView.this.o.a.a()) {
                                if (tiledServiceLayer.getUrl().equals(str5)) {
                                    MapView.this.a(tiledServiceLayer);
                                }
                            }
                        }
                    }
                    return b(i2, obj3);
                }
            }

            boolean a(int i2, Object obj) {
                if (MapView.this.y != null) {
                    MapView.this.y.onStatusChanged(obj, OnStatusChangedListener.STATUS.fromInt(i2));
                    return true;
                }
                return false;
            }

            boolean b(int i2, Object obj) {
                if (MapView.this.y != null) {
                    MapView.this.y.onStatusChanged(obj, OnStatusChangedListener.STATUS.fromInt(i2));
                    return true;
                }
                return false;
            }

            void a(Layer layer) {
                if (a(layer, -1) && MapView.this.y != null && MapView.this.a.e.get() == -1) {
                    MapView.this.y.onStatusChanged(MapView.this, OnStatusChangedListener.STATUS.INITIALIZATION_FAILED);
                }
            }

            private boolean a(Layer layer, int i2) {
                try {
                } catch (IndexOutOfBoundsException unused) {
                }
                synchronized (MapView.this.a.e) {
                    if (MapView.this.a.a.get(0).getID() != layer.getID() || MapView.this.a.e.get() == 1) {
                        return false;
                    }
                    if (i2 == 1) {
                        MapView.this.a.e.set(1);
                        return true;
                    }
                    return MapView.this.a.e.compareAndSet(0, -1);
                }
            }
        });
        this.t = null;
        this.u = null;
        this.v = null;
        this.w = null;
        this.x = null;
        this.y = null;
        this.P = false;
        this.Q = new MapAnimationListener() { // from class: com.esri.android.map.MapView.2
            {
                MapView.this = this;
            }

            @Override // com.esri.android.map.MapAnimationListener
            public void onAnimationFinished() {
                if (MapView.this.E || CalloutPopupWindow.a() > 0 || MapView.this.P) {
                    MapView.this.post(new Runnable() { // from class: com.esri.android.map.MapView.2.1
                        {
                            AnonymousClass2.this = this;
                        }

                        @Override // java.lang.Runnable
                        public void run() {
                            if (CalloutPopupWindow.a() > 0) {
                                CalloutPopupWindow.a(MapView.this);
                            }
                            if (MapView.this.E) {
                                MapView.this.l.a();
                                MapView.this.E = false;
                            }
                            if (MapView.this.P) {
                                MapView.this.P = false;
                                MapView.this.t.postAction(MapView.this.M, MapView.this.N, MapView.this.O);
                            }
                        }
                    });
                }
            }

            @Override // com.esri.android.map.MapAnimationListener
            public void onAnimating(boolean z) {
                if (z) {
                    MapView.this.e();
                }
            }
        };
        MapSurface a2 = a(context);
        this.a = a2;
        this.F = new Grid(a2);
        a(context, (AttributeSet) null);
        this.m = str;
        a(webMap);
        a((UserCredentials) null, new c.a(baseMap), (c.a) webMap, onMapEventListener);
    }

    public MapView(Context context, WebMap webMap, List<Layer> list, List<Layer> list2, String str, OnMapEventListener onMapEventListener) {
        super(context);
        this.z = false;
        this.A = true;
        this.f = Utils.DOUBLE_EPSILON;
        this.g = null;
        this.j = false;
        this.l = null;
        this.D = -1;
        this.E = false;
        this.m = null;
        this.n = null;
        this.F = null;
        this.p = false;
        this.q = false;
        this.r = false;
        this.s = new Handler(new Handler.Callback() { // from class: com.esri.android.map.MapView.1
            {
                MapView.this = this;
            }

            @Override // android.os.Handler.Callback
            public boolean handleMessage(Message message) {
                if (MapView.this.isRecycled()) {
                    return false;
                }
                int i2 = message.getData().getInt(NotificationCompat.CATEGORY_STATUS);
                OnStatusChangedListener.STATUS fromInt = OnStatusChangedListener.STATUS.fromInt(i2);
                MapView mapView = MapView.this;
                int i3 = AnonymousClass9.a[fromInt.ordinal()];
                if (i3 == 1) {
                    MapView.this.b();
                    if (MapView.this.l != null && MapView.this.l.isShowing()) {
                        MapView.this.l.show();
                    }
                    if (MapView.this.j && MapView.this.i != null) {
                        MapView.this.i.start();
                    }
                    return b(i2, mapView);
                } else if (i3 != 2) {
                    if (i3 == 3) {
                        if (message.obj == mapView) {
                            MapView.this.a.e.compareAndSet(0, -1);
                            return b(i2, mapView);
                        } else {
                            Object obj = message.obj;
                            boolean a2 = a(i2, obj);
                            a((Layer) obj);
                            return a2;
                        }
                    }
                    if (i3 != 4) {
                        return false;
                    }
                    Object obj2 = message.obj;
                    boolean a3 = a(i2, obj2);
                    a((Layer) obj2);
                    return a3;
                } else {
                    Object obj3 = message.obj;
                    Layer layer = (Layer) obj3;
                    MapView.this.a(layer);
                    if (a(layer, 1)) {
                        MapView.this.b();
                        if (MapView.this.y != null) {
                            MapView.this.y.onStatusChanged(MapView.this, OnStatusChangedListener.STATUS.INITIALIZED);
                        }
                    }
                    if (MapView.this.o != null && (obj3 instanceof TiledServiceLayer)) {
                        TiledServiceLayer tiledServiceLayer = (TiledServiceLayer) obj3;
                        if (MapView.this.o.a == MapOptions.MapType.OSM) {
                            MapView.this.a(tiledServiceLayer);
                        } else {
                            for (String str5 : MapView.this.o.a.a()) {
                                if (tiledServiceLayer.getUrl().equals(str5)) {
                                    MapView.this.a(tiledServiceLayer);
                                }
                            }
                        }
                    }
                    return b(i2, obj3);
                }
            }

            boolean a(int i2, Object obj) {
                if (MapView.this.y != null) {
                    MapView.this.y.onStatusChanged(obj, OnStatusChangedListener.STATUS.fromInt(i2));
                    return true;
                }
                return false;
            }

            boolean b(int i2, Object obj) {
                if (MapView.this.y != null) {
                    MapView.this.y.onStatusChanged(obj, OnStatusChangedListener.STATUS.fromInt(i2));
                    return true;
                }
                return false;
            }

            void a(Layer layer) {
                if (a(layer, -1) && MapView.this.y != null && MapView.this.a.e.get() == -1) {
                    MapView.this.y.onStatusChanged(MapView.this, OnStatusChangedListener.STATUS.INITIALIZATION_FAILED);
                }
            }

            private boolean a(Layer layer, int i2) {
                try {
                } catch (IndexOutOfBoundsException unused) {
                }
                synchronized (MapView.this.a.e) {
                    if (MapView.this.a.a.get(0).getID() != layer.getID() || MapView.this.a.e.get() == 1) {
                        return false;
                    }
                    if (i2 == 1) {
                        MapView.this.a.e.set(1);
                        return true;
                    }
                    return MapView.this.a.e.compareAndSet(0, -1);
                }
            }
        });
        this.t = null;
        this.u = null;
        this.v = null;
        this.w = null;
        this.x = null;
        this.y = null;
        this.P = false;
        this.Q = new MapAnimationListener() { // from class: com.esri.android.map.MapView.2
            {
                MapView.this = this;
            }

            @Override // com.esri.android.map.MapAnimationListener
            public void onAnimationFinished() {
                if (MapView.this.E || CalloutPopupWindow.a() > 0 || MapView.this.P) {
                    MapView.this.post(new Runnable() { // from class: com.esri.android.map.MapView.2.1
                        {
                            AnonymousClass2.this = this;
                        }

                        @Override // java.lang.Runnable
                        public void run() {
                            if (CalloutPopupWindow.a() > 0) {
                                CalloutPopupWindow.a(MapView.this);
                            }
                            if (MapView.this.E) {
                                MapView.this.l.a();
                                MapView.this.E = false;
                            }
                            if (MapView.this.P) {
                                MapView.this.P = false;
                                MapView.this.t.postAction(MapView.this.M, MapView.this.N, MapView.this.O);
                            }
                        }
                    });
                }
            }

            @Override // com.esri.android.map.MapAnimationListener
            public void onAnimating(boolean z) {
                if (z) {
                    MapView.this.e();
                }
            }
        };
        MapSurface a2 = a(context);
        this.a = a2;
        this.F = new Grid(a2);
        a(context, (AttributeSet) null);
        this.m = str;
        a(webMap);
        a((UserCredentials) null, new c.a(list, list2), (c.a) webMap, onMapEventListener);
    }

    public MapView(Context context, MapOptions mapOptions) {
        this(context);
        if (mapOptions != null) {
            this.o = mapOptions;
            d();
            return;
        }
        addLayer(new ArcGISTiledMapServiceLayer(MapOptions.MapType.TOPO.a()[0]));
    }

    private void a(WebMap webMap) {
        if (webMap == null) {
            throw new IllegalArgumentException(H);
        }
    }

    private void d() {
        if (this.o.a == MapOptions.MapType.OSM) {
            OpenStreetMapLayer openStreetMapLayer = new OpenStreetMapLayer();
            addLayer(openStreetMapLayer, 0);
            openStreetMapLayer.a(true);
            return;
        }
        for (String str : this.o.a.a()) {
            ArcGISTiledMapServiceLayer arcGISTiledMapServiceLayer = new ArcGISTiledMapServiceLayer(str);
            addLayer(arcGISTiledMapServiceLayer, 0);
            arcGISTiledMapServiceLayer.a(true);
        }
    }

    private void a(Context context, AttributeSet attributeSet) {
        if (isInEditMode()) {
            return;
        }
        setDrawingCacheQuality(524288);
        setAnimationCacheEnabled(false);
        setOnTouchListener(new MapOnTouchListener(context, this));
        setOnHierarchyChangeListener(this);
        setBackgroundColor(-12303292);
        a(attributeSet);
        getCallout();
        int i = this.D;
        if (i != -1) {
            this.l.setStyle(i);
        }
        a aVar = new a(getContext());
        this.n = aVar;
        addView(aVar);
    }

    private void a(AttributeSet attributeSet) {
        if (attributeSet == null) {
            return;
        }
        double d = Double.NaN;
        double d2 = Double.NaN;
        boolean z = false;
        String str = null;
        int i = -1;
        for (int i2 = 0; i2 < attributeSet.getAttributeCount(); i2++) {
            if ("initExtent".compareToIgnoreCase(attributeSet.getAttributeName(i2)) == 0) {
                String attributeValue = attributeSet.getAttributeValue(i2);
                if (attributeValue != null) {
                    String trim = attributeValue.trim();
                    if (trim.length() > 0) {
                        String[] split = trim.split(MinimalPrettyPrinter.DEFAULT_ROOT_VALUE_SEPARATOR);
                        try {
                            Envelope envelope = new Envelope(h.parse(split[0]).doubleValue(), h.parse(split[1]).doubleValue(), h.parse(split[2]).doubleValue(), h.parse(split[3]).doubleValue());
                            envelope.normalize();
                            setExtent(envelope, 0);
                        } catch (ParseException e) {
                            Log.e(com.esri.core.internal.a.a, "Can not parse MapView.initExtent from xml", e);
                        }
                    }
                }
            } else if ("gpsSymbol".equalsIgnoreCase(attributeSet.getAttributeName(i2))) {
                int attributeResourceValue = attributeSet.getAttributeResourceValue(i2, -1);
                if (attributeResourceValue != -1) {
                    this.k = getContext().getResources().getDrawable(attributeResourceValue);
                }
            } else if ("calloutStyle".equalsIgnoreCase(attributeSet.getAttributeName(i2))) {
                this.D = attributeSet.getAttributeResourceValue(i2, -1);
            } else if (TbsVideoCacheTask.KEY_VIDEO_CACHE_PARAM_URL.equalsIgnoreCase(attributeSet.getAttributeName(i2))) {
                a((UserCredentials) null, (c.a) null, (c.a) attributeSet.getAttributeValue(i2), (OnMapEventListener) null);
                z = true;
            } else if ("appId".equalsIgnoreCase(attributeSet.getAttributeName(i2))) {
                this.m = attributeSet.getAttributeValue(i2);
            } else if ("mapoptions.maptype".equalsIgnoreCase(attributeSet.getAttributeName(i2))) {
                str = attributeSet.getAttributeValue(i2);
            } else if ("mapoptions.center".equalsIgnoreCase(attributeSet.getAttributeName(i2))) {
                String attributeValue2 = attributeSet.getAttributeValue(i2);
                if (attributeValue2 != null) {
                    String trim2 = attributeValue2.trim();
                    if (trim2.length() > 0) {
                        String[] split2 = trim2.split(MinimalPrettyPrinter.DEFAULT_ROOT_VALUE_SEPARATOR);
                        try {
                            d = h.parse(split2[0]).doubleValue();
                            d2 = h.parse(split2[1]).doubleValue();
                        } catch (ParseException e2) {
                            Log.e(com.esri.core.internal.a.a, "Can not parse MapView.initExtent from xml", e2);
                        }
                    }
                }
            } else if ("mapoptions.zoomlevel".equalsIgnoreCase(attributeSet.getAttributeName(i2))) {
                i = attributeSet.getAttributeIntValue(i2, -1);
            }
        }
        if (z || TextUtils.isEmpty(str)) {
            return;
        }
        MapOptions mapOptions = new MapOptions(MapOptions.MapType.a(str));
        if (!Double.isNaN(d) && !Double.isNaN(d2)) {
            mapOptions.setCenter(d, d2);
        }
        if (i != -1) {
            mapOptions.setZoom(i);
        }
        this.o = mapOptions;
        d();
    }

    public void a(float f, float f2, float f3, float f4, boolean z) {
        float f5 = f - f3;
        float f6 = f2 - f4;
        if (isLoaded()) {
            OnPanListener onPanListener = this.u;
            if (onPanListener == null) {
                a(f5, f6, z);
                return;
            }
            onPanListener.prePointerMove(f, f2, f3, f4);
            a(f5, f6, z);
            this.u.postPointerMove(f, f2, f3, f4);
        }
    }

    void a(float f, float f2, boolean z) {
        if (f != 0.0f || f2 != 0.0f) {
            j();
            CalloutPopupWindow.a(this);
            this.a.a(-f, -f2, z);
            Callout callout = this.l;
            if (callout != null) {
                callout.a.k();
                this.l.a.a();
            }
        }
        postInvalidate();
    }

    public void b(float f, float f2, boolean z) {
        if (isLoaded()) {
            a(f, f2, 2.0d, z);
        }
    }

    public void zoomin() {
        zoomin(true);
    }

    public void zoomin(boolean z) {
        if (isLoaded()) {
            b(this.b, this.c, z);
        }
    }

    void c(float f, float f2, boolean z) {
        if (isLoaded()) {
            a(f, f2, 0.5d, z);
        }
    }

    public void zoomout() {
        zoomout(true);
    }

    public void zoomout(boolean z) {
        if (isLoaded()) {
            c(this.b, this.c, z);
        }
    }

    private void a(float f, float f2, double d, boolean z) {
        j();
        if (this.a.a(d, f, f2, z)) {
            e();
        }
        OnZoomListener onZoomListener = this.t;
        if (onZoomListener != null) {
            this.P = true;
            this.M = f;
            this.N = f2;
            this.O = d;
            onZoomListener.preAction(f, f2, d);
        }
    }

    public void e() {
        Callout callout = this.l;
        if (callout == null || !callout.isShowing()) {
            return;
        }
        if (Looper.getMainLooper().getThread() == Thread.currentThread()) {
            f();
        } else {
            post(new Runnable() { // from class: com.esri.android.map.MapView.4
                {
                    MapView.this = this;
                }

                @Override // java.lang.Runnable
                public void run() {
                    MapView.this.f();
                }
            });
        }
    }

    public void f() {
        this.l.hide();
        this.E = true;
    }

    @Override // android.view.ViewGroup
    public ViewGroup.LayoutParams generateLayoutParams(AttributeSet attributeSet) {
        return new ViewGroup.LayoutParams(-1, -1);
    }

    @Override // android.view.ViewGroup.OnHierarchyChangeListener
    public void onChildViewAdded(View view, View view2) {
        bringChildToFront(this.n);
    }

    <V> void a(final UserCredentials userCredentials, final c.a aVar, final V v, final OnMapEventListener onMapEventListener) {
        final c cVar = new c(this, aVar, (onMapEventListener == null || !(onMapEventListener instanceof OnWebMapLoadListener)) ? null : (OnWebMapLoadListener) onMapEventListener);
        MapSurface mapSurface = this.a;
        if (mapSurface != null) {
            mapSurface.c = new WeakReference<>(cVar);
        }
        if (v instanceof WebMap) {
            WebMap webMap = (WebMap) v;
            this.g = webMap.getInitExtent();
            cVar.execute(webMap);
            return;
        }
        try {
            WebMap.newInstance(new URL((String) v), userCredentials, new CallbackListener<WebMap>() { // from class: com.esri.android.map.MapView.5
                {
                    MapView.this = this;
                }

                @Override // com.esri.core.map.CallbackListener
                public void onError(Throwable th) {
                    OnMapEventListener onMapEventListener2 = onMapEventListener;
                    if (onMapEventListener2 != null && (onMapEventListener2 instanceof OnWebMapLoadListener)) {
                        MapLoadAction<UserCredentials> onWebMapLoadError = ((OnWebMapLoadListener) onMapEventListener2).onWebMapLoadError(MapView.this, null, null, null, th, userCredentials);
                        if (onWebMapLoadError == null || onWebMapLoadError.getAction() == null) {
                            return;
                        }
                        if (AnonymousClass9.b[onWebMapLoadError.getAction().ordinal()] == 1) {
                            Log.i(com.esri.core.internal.a.a, "WebMap Action: CONTINUE_OPEN_WITH_THE_PARAMETER");
                            MapView.this.a(onWebMapLoadError.getParameter(), aVar, (c.a) v, onMapEventListener);
                            return;
                        }
                        Log.i(com.esri.core.internal.a.a, "WebMap Action: CANCEL_OPEN");
                        return;
                    }
                    MapView.this.a(th);
                }

                @Override // com.esri.core.map.CallbackListener
                /* renamed from: a */
                public void onCallback(WebMap webMap2) {
                    MapView.this.g = webMap2.getInitExtent();
                    cVar.execute(webMap2);
                }
            });
        } catch (MalformedURLException e) {
            a(e);
        }
    }

    /* renamed from: com.esri.android.map.MapView$9 */
    /* loaded from: classes.dex */
    static /* synthetic */ class AnonymousClass9 {
        static final /* synthetic */ int[] a;
        static final /* synthetic */ int[] b;

        static {
            int[] iArr = new int[MapLoadAction.Action.values().length];
            b = iArr;
            try {
                iArr[MapLoadAction.Action.CONTINUE_OPEN_WITH_THE_PARAMETER.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                b[MapLoadAction.Action.CONTINUE_OPEN_AND_SKIP_CURRENT_LAYER.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            try {
                b[MapLoadAction.Action.CANCEL_OPEN.ordinal()] = 3;
            } catch (NoSuchFieldError unused3) {
            }
            int[] iArr2 = new int[OnStatusChangedListener.STATUS.values().length];
            a = iArr2;
            try {
                iArr2[OnStatusChangedListener.STATUS.INITIALIZED.ordinal()] = 1;
            } catch (NoSuchFieldError unused4) {
            }
            try {
                a[OnStatusChangedListener.STATUS.LAYER_LOADED.ordinal()] = 2;
            } catch (NoSuchFieldError unused5) {
            }
            try {
                a[OnStatusChangedListener.STATUS.INITIALIZATION_FAILED.ordinal()] = 3;
            } catch (NoSuchFieldError unused6) {
            }
            try {
                a[OnStatusChangedListener.STATUS.LAYER_LOADING_FAILED.ordinal()] = 4;
            } catch (NoSuchFieldError unused7) {
            }
        }
    }

    public void a(Throwable th) {
        if (isRecycled()) {
            return;
        }
        a(OnStatusChangedListener.STATUS.fromInt(OnStatusChangedListener.EsriStatusException.INIT_FAILED_WEBMAP));
        Log.e(com.esri.core.internal.a.a, "Can not init the MapView from the given WebMap", th);
    }

    @Override // android.view.View
    protected void onMeasure(int i, int i2) {
        int childCount = getChildCount();
        for (int i3 = 0; i3 < childCount; i3++) {
            View childAt = getChildAt(i3);
            if (childAt.getVisibility() != 8) {
                measureChild(childAt, i, i2);
            }
        }
        setMeasuredDimension(resolveSize(getPaddingLeft() + getPaddingRight() + 0, i), resolveSize(0 + getPaddingTop() + getPaddingBottom(), i2));
    }

    @Override // android.view.ViewGroup, android.view.View
    protected void onLayout(boolean z, int i, int i2, int i3, int i4) {
        int childCount = super.getChildCount();
        for (int i5 = 0; i5 < childCount; i5++) {
            View childAt = getChildAt(i5);
            if (childAt.getVisibility() != 8) {
                int paddingLeft = getPaddingLeft();
                int paddingTop = getPaddingTop();
                childAt.layout(paddingLeft, paddingTop, childAt.getMeasuredWidth() + paddingLeft, childAt.getMeasuredHeight() + paddingTop);
            }
        }
    }

    public String retainState() {
        if (isLoaded()) {
            StringBuilder sb = new StringBuilder();
            Point center = getCenter();
            if (center == null || center.isEmpty()) {
                sb.append(Double.NaN);
                sb.append(MinimalPrettyPrinter.DEFAULT_ROOT_VALUE_SEPARATOR);
                sb.append(Double.NaN);
                sb.append(MinimalPrettyPrinter.DEFAULT_ROOT_VALUE_SEPARATOR);
            } else {
                SpatialReference spatialReference = getSpatialReference();
                if (spatialReference != null) {
                    center = (Point) GeometryEngine.normalizeCentralMeridian(center, spatialReference);
                }
                sb.append(center.getX());
                sb.append(MinimalPrettyPrinter.DEFAULT_ROOT_VALUE_SEPARATOR);
                sb.append(center.getY());
                sb.append(MinimalPrettyPrinter.DEFAULT_ROOT_VALUE_SEPARATOR);
            }
            double resolution = getResolution();
            if (Double.isNaN(resolution) || resolution <= Utils.DOUBLE_EPSILON) {
                sb.append(Double.NaN);
                sb.append(MinimalPrettyPrinter.DEFAULT_ROOT_VALUE_SEPARATOR);
            } else {
                sb.append(resolution);
                sb.append(MinimalPrettyPrinter.DEFAULT_ROOT_VALUE_SEPARATOR);
            }
            LocationDisplayManager locationDisplayManager = this.i;
            if (locationDisplayManager != null && locationDisplayManager.isStarted()) {
                sb.append(1);
                sb.append(MinimalPrettyPrinter.DEFAULT_ROOT_VALUE_SEPARATOR);
                sb.append(this.i.getAutoPanMode().getValue());
            } else {
                sb.append(0);
                sb.append(MinimalPrettyPrinter.DEFAULT_ROOT_VALUE_SEPARATOR);
                sb.append(LocationDisplayManager.AutoPanMode.OFF.getValue());
            }
            return sb.toString();
        }
        return "";
    }

    public void restoreState(String str) {
        String[] split;
        boolean z;
        MapOptions mapOptions;
        if (str == null || str.trim().length() <= 0 || (split = str.split(MinimalPrettyPrinter.DEFAULT_ROOT_VALUE_SEPARATOR)) == null || split.length != 5) {
            return;
        }
        double parseDouble = Double.parseDouble(split[0]);
        boolean z2 = true;
        double parseDouble2 = Double.parseDouble(split[1]);
        double parseDouble3 = Double.parseDouble(split[2]);
        if (Integer.parseInt(split[3]) == 1) {
            LocationDisplayManager locationDisplayManager = new LocationDisplayManager(this);
            this.i = locationDisplayManager;
            locationDisplayManager.setAutoPanMode(LocationDisplayManager.AutoPanMode.values()[Integer.parseInt(split[4])]);
            this.i.start();
        }
        if (Double.isNaN(parseDouble) || Double.isNaN(parseDouble2)) {
            z = false;
        } else {
            centerAt(new Point(parseDouble, parseDouble2), false);
            z = true;
        }
        if (this.a == null || Double.isNaN(parseDouble3)) {
            z2 = z;
        } else {
            this.a.b(parseDouble3, false);
        }
        if (!z2 || (mapOptions = this.o) == null) {
            return;
        }
        this.o = new MapOptions(mapOptions.a);
    }

    @Override // android.view.View
    protected void onSizeChanged(int i, int i2, int i3, int i4) {
        this.b = i / 2;
        this.c = i2 / 2;
        this.d = i;
        this.e = i2;
    }

    public void a(MotionEvent motionEvent, MotionEvent motionEvent2, float f, float f2, boolean z) {
        b(motionEvent, motionEvent2, f, f2, z);
    }

    private void b(MotionEvent motionEvent, MotionEvent motionEvent2, float f, float f2, boolean z) {
        boolean z2;
        j();
        float eventTime = (float) (motionEvent2.getEventTime() - motionEvent.getEventTime());
        float f3 = (f / 1000.0f) * eventTime;
        float f4 = eventTime * (f2 / 1000.0f);
        if (this.a == null || isRecycled()) {
            return;
        }
        if (this.u == null) {
            z2 = this.a.a(f3, f4, z);
        } else {
            float x = motionEvent.getX() + f3;
            float y = motionEvent.getY() + f4;
            this.u.prePointerMove(motionEvent.getX(), motionEvent.getY(), x, y);
            boolean a2 = this.a.a(f3, f4, z);
            this.u.postPointerMove(motionEvent.getX(), motionEvent.getY(), x, y);
            this.u.prePointerUp(motionEvent.getX(), motionEvent.getY(), x, y);
            this.u.postPointerUp(motionEvent.getX(), motionEvent.getY(), x, y);
            z2 = a2;
        }
        if (z2) {
            e();
        }
    }

    public void a(float f, float f2, float f3, float f4) {
        this.B = (f + f3) / 2.0f;
        this.C = (f2 + f4) / 2.0f;
        if (isLoaded()) {
            OnPinchListener onPinchListener = this.w;
            if (onPinchListener == null) {
                b(this.B, this.C);
            } else {
                onPinchListener.prePointersDown(f, f2, f3, f4, 1.0d);
                b(this.B, this.C);
                this.w.postPointersDown(f, f2, f3, f4, 1.0d);
            }
            OnZoomListener onZoomListener = this.t;
            if (onZoomListener != null) {
                onZoomListener.preAction(this.B, this.C, 1.0d);
            }
        }
    }

    public boolean isAllowOneFingerZoom() {
        return this.A;
    }

    public void setAllowOneFingerZoom(boolean z) {
        this.A = z;
    }

    public boolean isAllowRotationByPinch() {
        return this.z;
    }

    public void setAllowRotationByPinch(boolean z) {
        this.z = z;
    }

    public void a(float f, float f2, float f3, float f4, float f5, double d, boolean z) {
        if (this.a != null) {
            this.B = (f + f3) / 2.0f;
            this.C = (f2 + f4) / 2.0f;
        }
        if (isLoaded()) {
            OnPinchListener onPinchListener = this.w;
            if (onPinchListener == null) {
                a(this.B, this.C, f5, d, z);
                return;
            }
            double d2 = f5;
            onPinchListener.prePointersMove(f, f2, f3, f4, d2);
            a(this.B, this.C, f5, d, z);
            this.w.postPointersMove(f, f2, f3, f4, d2);
        }
    }

    private void a(float f, float f2, float f3, double d, boolean z) {
        j();
        if (z && this.z) {
            this.a.a(f3, this.B, this.C, false);
            MapSurface mapSurface = this.a;
            mapSurface.c(mapSurface.m() + d, this.B, this.C, false);
            return;
        }
        this.a.a(f3, this.B, this.C, false);
    }

    public void a(float f) {
        j();
        Point screenPoint = toScreenPoint(getCenter());
        if (isLoaded() && screenPoint != null && this.a.a(f, (float) screenPoint.getX(), (float) screenPoint.getY(), false)) {
            e();
        }
    }

    public void a(float f, float f2, float f3, float f4, float f5) {
        if (isLoaded()) {
            OnPinchListener onPinchListener = this.w;
            if (onPinchListener == null) {
                a(this.B, this.C, f5);
            } else {
                double d = f5;
                onPinchListener.prePointersUp(f, f2, f3, f4, d);
                a(this.B, this.C, f5);
                this.w.postPointersUp(f, f2, f3, f4, d);
            }
            OnZoomListener onZoomListener = this.t;
            if (onZoomListener != null) {
                onZoomListener.postAction(this.B, this.C, f5);
            }
        }
        this.B = 0.0f;
        this.C = 0.0f;
    }

    public Point getCenter() {
        if (isLoaded()) {
            return this.a.g();
        }
        return null;
    }

    public double getResolution() {
        if (isLoaded()) {
            return this.a.f();
        }
        return Double.NaN;
    }

    public void setResolution(double d) {
        if (Double.isNaN(d) || this.a == null) {
            return;
        }
        j();
        if (this.a.b(d, true)) {
            e();
        }
    }

    public SpatialReference getSpatialReference() {
        if (isLoaded()) {
            return this.a.j();
        }
        return null;
    }

    public void removeLayer(Layer layer) {
        MapSurface mapSurface = this.a;
        if (mapSurface != null) {
            int indexOf = mapSurface.a.indexOf(layer);
            if (indexOf >= 0) {
                this.a.a(indexOf);
                g();
                return;
            }
            throw new RuntimeException("The layer is not a sub-layer of the current map.");
        }
    }

    public int addLayer(Layer layer) {
        return addLayer(layer, -1);
    }

    public void addLayers(Layer[] layerArr) {
        if (layerArr != null) {
            for (Layer layer : layerArr) {
                addLayer(layer);
            }
        }
    }

    public int addLayer(Layer layer, int i) {
        if (this.a == null || layer == null) {
            return -1;
        }
        if (layer instanceof TiledServiceLayer) {
            TiledServiceLayer tiledServiceLayer = (TiledServiceLayer) layer;
            tiledServiceLayer.b(a(getContext(), tiledServiceLayer, this.a.l, this.a.l().length));
        }
        int a2 = this.a.a(layer, i);
        a(layer);
        return a2;
    }

    public void removeLayer(int i) {
        MapSurface mapSurface = this.a;
        if (mapSurface != null) {
            mapSurface.a(i);
            g();
        }
    }

    public void removeAll() {
        MapSurface mapSurface = this.a;
        if (mapSurface != null) {
            mapSurface.k();
            a aVar = this.n;
            if (aVar != null) {
                aVar.a(false, (BingMapsLayer) null);
            }
        }
    }

    private void g() {
        boolean z;
        a aVar;
        Layer[] layers = getLayers();
        if (layers == null || layers.length <= 0) {
            return;
        }
        int length = layers.length;
        int i = 0;
        while (true) {
            if (i >= length) {
                z = true;
                break;
            } else if (layers[i] instanceof BingMapsLayer) {
                z = false;
                break;
            } else {
                i++;
            }
        }
        if (!z || (aVar = this.n) == null) {
            return;
        }
        aVar.a(false, (BingMapsLayer) null);
    }

    public Layer getLayerByURL(String str) {
        MapSurface mapSurface = this.a;
        if (mapSurface == null) {
            return null;
        }
        for (Layer layer : mapSurface.a) {
            String url = layer.getUrl();
            if (url != null && url.equals(str)) {
                return layer;
            }
        }
        return null;
    }

    public Layer getLayerByID(long j) {
        Layer[] layers;
        Layer layer = null;
        if (this.a == null || j == 0) {
            return null;
        }
        for (Layer layer2 : getLayers()) {
            long id = layer2.getID();
            if (id != 0) {
                if (id == j) {
                    return layer2;
                }
                if ((layer2 instanceof GroupLayer) && (layer = ((GroupLayer) layer2).getLayerByID(j)) != null) {
                    return layer;
                }
            }
        }
        return layer;
    }

    public Layer[] getLayers() {
        MapSurface mapSurface = this.a;
        if (mapSurface == null) {
            return null;
        }
        return mapSurface.l();
    }

    public Layer getLayer(int i) {
        MapSurface mapSurface = this.a;
        if (mapSurface == null) {
            return null;
        }
        return mapSurface.a.get(i);
    }

    public void setMapBackground(int i, int i2, float f, float f2) {
        MapSurface mapSurface = this.a;
        if (mapSurface != null) {
            mapSurface.a(i, i2, f, f2);
        }
    }

    private boolean a(SpatialReference spatialReference, Envelope envelope) {
        MapSurface mapSurface = this.a;
        if (mapSurface == null || spatialReference == null || envelope == null) {
            return false;
        }
        return mapSurface.a(spatialReference, envelope);
    }

    public Polygon getExtent() {
        MapSurface mapSurface = this.a;
        if (mapSurface != null) {
            return mapSurface.i();
        }
        return null;
    }

    public Envelope getMaxExtent() {
        MapSurface mapSurface = this.a;
        if (mapSurface != null) {
            return mapSurface.h();
        }
        return null;
    }

    @Deprecated
    public Envelope getMapBoundaryExtent() {
        MapSurface mapSurface = this.a;
        if (mapSurface != null) {
            return mapSurface.h();
        }
        return null;
    }

    public void setMaxExtent(Envelope envelope) {
        MapSurface mapSurface = this.a;
        if (mapSurface != null) {
            mapSurface.a(envelope);
        }
    }

    public void setExtent(Geometry geometry) {
        setExtent(geometry, 0);
    }

    public void setExtent(Geometry geometry, int i) {
        setExtent(geometry, i, true);
    }

    public void setExtent(Geometry geometry, int i, boolean z) {
        if (this.a != null) {
            j();
            if (this.a.a(geometry, i, z)) {
                e();
            }
        }
    }

    public void zoomTo(Point point, float f) {
        j();
        if (isLoaded()) {
            double resolution = getResolution();
            if (Double.isNaN(resolution) || resolution <= Utils.DOUBLE_EPSILON) {
                return;
            }
            double d = f;
            Double.isNaN(d);
            if (this.a.a(point, resolution / d, true)) {
                e();
                return;
            }
            return;
        }
        centerAt(point, false);
    }

    public void centerAt(Point point, boolean z) {
        if (this.a != null) {
            j();
            if (this.a.a(point, z)) {
                e();
            }
        }
    }

    public void centerAt(double d, double d2, boolean z) {
        Point point;
        SpatialReference spatialReference = getSpatialReference();
        if (spatialReference == null) {
            return;
        }
        if (!spatialReference.isWGS84()) {
            point = GeometryEngine.project(d2, d, getSpatialReference());
        } else {
            point = new Point(d2, d);
        }
        centerAt(point, z);
    }

    public void centerAndZoom(double d, double d2, float f) {
        Layer[] layers;
        double resolution = getResolution();
        if (f <= 0.0f || Double.isNaN(resolution) || resolution <= Utils.DOUBLE_EPSILON) {
            return;
        }
        for (Layer layer : getLayers()) {
            if (layer.isWebMapBaselayer() && (layer instanceof TiledServiceLayer)) {
                TiledServiceLayer tiledServiceLayer = (TiledServiceLayer) layer;
                int i = (int) f;
                int levels = tiledServiceLayer.getTileInfo().getLevels() - 1;
                a(tiledServiceLayer, d, d2, i > levels ? levels : i);
                return;
            }
        }
        centerAt(d, d2, true);
        double resolution2 = getResolution();
        double d3 = f;
        Double.isNaN(d3);
        setResolution(resolution2 * d3);
    }

    public Point toScreenPoint(Point point) {
        MapSurface mapSurface = this.a;
        if (mapSurface == null || point == null) {
            return null;
        }
        return mapSurface.a(point);
    }

    public Point toMapPoint(Point point) {
        MapSurface mapSurface = this.a;
        if (mapSurface == null || point == null) {
            return null;
        }
        return mapSurface.b(point);
    }

    public Point toMapPoint(float f, float f2) {
        MapSurface mapSurface = this.a;
        if (mapSurface == null) {
            return null;
        }
        return mapSurface.a(f, f2);
    }

    public double getScale() {
        MapSurface mapSurface = this.a;
        return mapSurface == null ? Utils.DOUBLE_EPSILON : mapSurface.d();
    }

    public void setScale(double d) {
        setScale(d, true);
    }

    public void setScale(double d, boolean z) {
        if (Double.isNaN(d) || this.a == null) {
            return;
        }
        j();
        if (this.a.a(d, z)) {
            e();
        }
    }

    public OnZoomListener getOnZoomListener() {
        return this.t;
    }

    public void setOnZoomListener(OnZoomListener onZoomListener) {
        this.t = onZoomListener;
    }

    public OnPanListener getOnPanListener() {
        return this.u;
    }

    public void setOnPanListener(OnPanListener onPanListener) {
        this.u = onPanListener;
    }

    public OnLongPressListener getOnLongPressListener() {
        return this.v;
    }

    public void setOnLongPressListener(OnLongPressListener onLongPressListener) {
        this.v = onLongPressListener;
    }

    public OnPinchListener getOnPinchListener() {
        return this.w;
    }

    public void setOnPinchListener(OnPinchListener onPinchListener) {
        this.w = onPinchListener;
    }

    public OnSingleTapListener getOnSingleTapListener() {
        return this.x;
    }

    public void setOnSingleTapListener(OnSingleTapListener onSingleTapListener) {
        this.x = onSingleTapListener;
    }

    public OnStatusChangedListener getOnStatusChangedListener() {
        return this.y;
    }

    public void setOnStatusChangedListener(OnStatusChangedListener onStatusChangedListener) {
        this.y = onStatusChangedListener;
    }

    public void a(OnStatusChangedListener.STATUS status) {
        Message obtainMessage = this.s.obtainMessage();
        Bundle bundle = new Bundle();
        bundle.putInt(NotificationCompat.CATEGORY_STATUS, status.getValue());
        obtainMessage.setData(bundle);
        obtainMessage.obj = this;
        this.s.sendMessage(obtainMessage);
    }

    public boolean isLoaded() {
        MapSurface mapSurface = this.a;
        if (mapSurface == null) {
            return false;
        }
        return mapSurface.b();
    }

    public boolean a() {
        MapSurface mapSurface = this.a;
        boolean c = mapSurface == null ? false : mapSurface.c();
        if (c) {
            this.E = true;
        }
        return !c;
    }

    public LocationDisplayManager getLocationDisplayManager() {
        if (this.i == null) {
            this.i = new LocationDisplayManager(this);
        }
        return this.i;
    }

    public Callout getCallout() {
        if (this.l == null) {
            Callout callout = new Callout(this);
            this.l = callout;
            addView(callout.a, new ViewGroup.LayoutParams(-1, -1));
        }
        return this.l;
    }

    public void recycle() {
        LocationDisplayManager locationDisplayManager = this.i;
        if (locationDisplayManager != null) {
            locationDisplayManager.a();
        }
        MapSurface mapSurface = this.a;
        if (mapSurface != null) {
            mapSurface.finalize();
        }
    }

    public void setRotationAngle(double d) {
        setRotationAngle(d, true);
    }

    public void setRotationAngle(double d, boolean z) {
        this.f = d;
        if (this.a == null || isRecycled() || !this.a.c(d, z)) {
            return;
        }
        e();
    }

    public void setRotationAngle(double d, Point point, boolean z) {
        this.f = d;
        if (this.a != null) {
            double rotationAngle = getRotationAngle();
            if (z && isLoaded()) {
                if (Math.abs(rotationAngle - d) > 0.01d) {
                    Point center = getCenter();
                    if (center == null || center.isEmpty() || this.a == null || isRecycled()) {
                        return;
                    }
                    centerAt(point, true);
                    setRotationAngle(d);
                    return;
                }
                centerAt(point, true);
                return;
            }
            centerAt(point, false);
            setRotationAngle(d, false);
        }
    }

    public void setRotationAngle(double d, float f, float f2) {
        this.f = d;
        MapSurface mapSurface = this.a;
        if (mapSurface == null || !mapSurface.c(d, f, f2, true)) {
            return;
        }
        e();
    }

    public double getRotationAngle() {
        MapSurface mapSurface = this.a;
        return mapSurface == null ? Utils.DOUBLE_EPSILON : mapSurface.m();
    }

    public void pause() {
        LocationDisplayManager locationDisplayManager = this.i;
        if (locationDisplayManager != null && locationDisplayManager.isStarted()) {
            this.i.pause();
        }
        MapSurface mapSurface = this.a;
        if (mapSurface == null || !mapSurface.b()) {
            return;
        }
        this.a.a(false);
    }

    public void unpause() {
        LocationDisplayManager locationDisplayManager = this.i;
        if (locationDisplayManager != null && locationDisplayManager.isStarted()) {
            this.i.resume();
        }
        MapSurface mapSurface = this.a;
        if (mapSurface == null || !mapSurface.b()) {
            return;
        }
        this.a.e();
    }

    public void zoomToScale(Point point, double d) {
        if (Double.isNaN(d) || this.a == null) {
            return;
        }
        j();
        if (this.a.a(d, point)) {
            e();
        }
    }

    public void zoomToResolution(Point point, double d) {
        centerAt(point, true);
        setResolution(d);
    }

    public void a(TiledServiceLayer tiledServiceLayer) {
        MapOptions mapOptions = this.o;
        if (mapOptions == null || mapOptions.e) {
            return;
        }
        a(tiledServiceLayer, this.o.b, this.o.c, this.o.d > tiledServiceLayer.getTileInfo().getLevels() + (-1) ? tiledServiceLayer.getTileInfo().getLevels() - 1 : this.o.d);
    }

    private void a(TiledServiceLayer tiledServiceLayer, double d, double d2, int i) {
        centerAt((Point) GeometryEngine.project(new Point(d2, d), SpatialReference.create(SpatialReference.WKID_WGS84), getSpatialReference()), false);
        setResolution(tiledServiceLayer.getTileInfo().getResolutions()[i]);
    }

    void b() {
        h();
    }

    private void h() {
        MapSurface mapSurface = this.a;
        if (mapSurface == null) {
            return;
        }
        double d = this.f;
        if (((int) d) != 0) {
            mapSurface.c(d, false);
        }
        Envelope envelope = this.g;
        if (envelope == null || envelope.isEmpty()) {
            return;
        }
        Envelope envelope2 = this.g;
        SpatialReference j = this.a.j();
        if (j != null && j.getID() != 4326) {
            envelope2 = (Envelope) GeometryEngine.project(envelope2, SpatialReference.create(4326), j);
        }
        if (envelope2 == null || envelope2.isEmpty()) {
            return;
        }
        Point center = envelope2.getCenter();
        double width = envelope2.getWidth();
        double d2 = this.d;
        Double.isNaN(d2);
        this.a.a(center, width / d2, false);
    }

    @Override // android.view.ViewGroup, android.view.View
    protected void onDetachedFromWindow() {
        LocationDisplayManager locationDisplayManager = this.i;
        if (locationDisplayManager != null && locationDisplayManager.isStarted()) {
            this.i.stop();
        }
        super.onDetachedFromWindow();
        if (this.a.b()) {
            synchronized (this.a.a) {
                for (Layer layer : this.a.a) {
                    if (layer instanceof ArcGISFeatureLayer) {
                        ((ArcGISFeatureLayer) layer).clear();
                    }
                    if (layer instanceof KMLLayer) {
                        a((KMLLayer) layer);
                    }
                }
            }
        }
    }

    private void a(KMLLayer kMLLayer) {
        Layer[] layers;
        kMLLayer.setVisible(false);
        if (kMLLayer.getLayers() == null || kMLLayer.getLayers().length <= 0) {
            return;
        }
        for (Layer layer : kMLLayer.getLayers()) {
            if (layer instanceof KMLLayer) {
                a((KMLLayer) layer);
            }
        }
    }

    @Deprecated
    public double getMinResolution() {
        return this.a.n();
    }

    @Deprecated
    public void setMinResolution(double d) {
        this.a.b(d);
    }

    @Deprecated
    public double getMaxResolution() {
        return this.a.o();
    }

    @Deprecated
    public void setMaxResolution(double d) {
        this.a.c(d);
    }

    public Grid getGrid() {
        return this.F;
    }

    void a(final Layer layer) {
        Handler handler;
        if (layer == null || !(layer instanceof BingMapsLayer) || (handler = this.s) == null) {
            return;
        }
        handler.post(new Runnable() { // from class: com.esri.android.map.MapView.6
            {
                MapView.this = this;
            }

            @Override // java.lang.Runnable
            public void run() {
                MapView.this.n.a(true, (BingMapsLayer) layer);
            }
        });
    }

    public void setEsriLogoVisible(final boolean z) {
        Handler handler = this.s;
        if (handler != null) {
            handler.post(new Runnable() { // from class: com.esri.android.map.MapView.7
                {
                    MapView.this = this;
                }

                @Override // java.lang.Runnable
                public void run() {
                    MapView.this.n.a(z);
                }
            });
        }
    }

    public Bitmap getDrawingMapCache(float f, float f2, int i, int i2) {
        Bitmap a2;
        if (f >= 0.0f && f2 >= 0.0f && i > 0 && i2 > 0 && (a2 = this.a.a(0.0f, 0.0f, getWidth(), getHeight())) != null) {
            if (i > getWidth() - f) {
                i = (int) (getWidth() - f);
            }
            if (i2 > getHeight() - f2) {
                i2 = (int) (getHeight() - f2);
            }
            if (i > 0 && i2 > 0) {
                return Bitmap.createBitmap(a2, (int) f, (int) f2, i, i2);
            }
        }
        return null;
    }

    public void setShowMagnifierOnLongPress(boolean z) {
        if (!this.p && z) {
            this.p = true;
            i();
        }
        this.q = z;
    }

    public boolean isShowMagnifierOnLongPress() {
        return this.q;
    }

    public void setAllowMagnifierToPanMap(boolean z) {
        if (!this.p && z) {
            this.p = true;
            i();
        }
        this.r = z;
    }

    /* loaded from: classes.dex */
    public static class a extends LinearLayout {
        static final String c = "res/G39405_Esri1.png";
        static final double d = 8.92264981E9d;
        ImageView a;
        ImageView b;

        public a(Context context) {
            super(context);
            this.a = null;
            this.b = null;
            setGravity(80);
            setLayoutParams(new LinearLayout.LayoutParams(-1, -1));
            setPadding(5, 0, 0, 5);
        }

        void a(boolean z) {
            if (!z) {
                View view = this.b;
                if (view != null) {
                    removeView(view);
                    this.b = null;
                }
            } else if (this.b == null) {
                Bitmap a = a();
                if (a != null) {
                    ImageView imageView = new ImageView(getContext());
                    this.b = imageView;
                    imageView.setBackgroundDrawable(null);
                    this.b.setClickable(false);
                    this.b.setImageBitmap(a);
                    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(-2, -2);
                    layoutParams.rightMargin = 8;
                    layoutParams.bottomMargin = 5;
                    if (this.b.getParent() == null) {
                        addView(this.b, 0, layoutParams);
                        return;
                    }
                    return;
                }
                Log.e(com.esri.core.internal.a.a, "fails to add ESRI logo for invalid image supplied");
            }
        }

        void a(boolean z, BingMapsLayer bingMapsLayer) {
            ImageView imageView;
            if (!z && (imageView = this.a) != null) {
                removeView(imageView);
                this.a = null;
            } else if (bingMapsLayer == null || this.a != null) {
            } else {
                Bitmap a = a(bingMapsLayer);
                if (a != null) {
                    ImageView imageView2 = new ImageView(getContext());
                    this.a = imageView2;
                    imageView2.setBackgroundDrawable(null);
                    this.a.setClickable(false);
                    this.a.setImageBitmap(a);
                    addView(this.a);
                    return;
                }
                Log.e(com.esri.core.internal.a.a, "fail to add the Bing Map Logo.");
            }
        }

        private Bitmap a() {
            return b(false, null);
        }

        private Bitmap a(BingMapsLayer bingMapsLayer) {
            return b(true, bingMapsLayer);
        }

        private Bitmap b(boolean z, BingMapsLayer bingMapsLayer) {
            DisplayMetrics displayMetrics;
            int i;
            ((WindowManager) getContext().getSystemService("window")).getDefaultDisplay().getMetrics(new DisplayMetrics());
            float sqrt = (float) Math.sqrt(displayMetrics.xdpi * displayMetrics.ydpi);
            MapView mapView = (MapView) getParent();
            double min = Math.min(mapView.getWidth(), mapView.getHeight()) / sqrt;
            if (min <= 2.7d) {
                double d2 = sqrt;
                Double.isNaN(d2);
                i = (int) (d2 * 0.47d);
            } else if (min > 2.7d) {
                double d3 = sqrt;
                Double.isNaN(d3);
                i = (int) (d3 * 0.6d);
            } else {
                i = 90;
            }
            double d4 = i;
            Double.isNaN(d4);
            int i2 = (int) (d4 / 2.8d);
            if (z) {
                return bingMapsLayer.getBingLogo(i, i2);
            }
            return a(i, i2);
        }

        private Bitmap a(int i, int i2) {
            InputStream resourceAsStream = getClass().getResourceAsStream(c);
            BitmapFactory.Options options = new BitmapFactory.Options();
            options.outWidth = i;
            options.outHeight = i2;
            options.inPurgeable = true;
            Bitmap decodeStream = BitmapFactory.decodeStream(resourceAsStream, null, options);
            if (a(decodeStream, decodeStream.getWidth() / 2, decodeStream.getHeight() / 2, d)) {
                return decodeStream;
            }
            return null;
        }

        private boolean a(Bitmap bitmap, int i, int i2, double d2) {
            double d3 = Utils.DOUBLE_EPSILON;
            for (int i3 = 0; i3 < 3; i3++) {
                for (int i4 = 0; i4 < 3; i4++) {
                    double pixel = bitmap.getPixel(i + i3, i2 + i4);
                    Double.isNaN(pixel);
                    d3 += pixel;
                }
            }
            return d2 == d3;
        }
    }

    public boolean isRecycled() {
        try {
            MapSurface mapSurface = this.a;
            if (mapSurface != null) {
                return mapSurface.b.get();
            }
            return true;
        } catch (Exception unused) {
            return true;
        }
    }

    public void enableWrapAround(boolean z) {
        MapSurface mapSurface = this.a;
        if (mapSurface != null) {
            mapSurface.b(z);
        }
    }

    protected void finalize() throws Throwable {
        try {
            super.finalize();
        } finally {
            recycle();
        }
    }

    @Deprecated
    public Bitmap createSymbolImage(Symbol symbol, Geometry geometry, int i, int i2, int i3) {
        MapSurface mapSurface = this.a;
        if (mapSurface == null) {
            throw new UnsupportedOperationException("The method is only supported on layers added to MapView.");
        }
        return mapSurface.a(symbol, geometry, i, i2, i3);
    }

    @Deprecated
    public Bitmap[] createSymbolImages(Symbol[] symbolArr, Geometry[] geometryArr, int i, int i2, int i3) {
        MapSurface mapSurface = this.a;
        if (mapSurface == null) {
            throw new UnsupportedOperationException("The method is only supported on layers added to MapView.");
        }
        return mapSurface.a(symbolArr, geometryArr, i, i2, i3);
    }

    private void i() {
        try {
            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inPreferredConfig = Bitmap.Config.ARGB_8888;
            DisplayMetrics displayMetrics = new DisplayMetrics();
            ((WindowManager) getContext().getSystemService("window")).getDefaultDisplay().getMetrics(displayMetrics);
            Class<?> cls = getClass();
            Bitmap decodeStream = BitmapFactory.decodeStream(cls.getResourceAsStream("/com/esri/android/map/res/MagnifierMask.png"), null, options);
            Class<?> cls2 = getClass();
            Bitmap decodeStream2 = BitmapFactory.decodeStream(cls2.getResourceAsStream("/com/esri/android/map/res/Magnifier.png"), null, options);
            if (displayMetrics.densityDpi >= 320) {
                Class<?> cls3 = getClass();
                decodeStream = BitmapFactory.decodeStream(cls3.getResourceAsStream("/com/esri/android/map/res/MagnifierMask@2x.png"), null, options);
                Class<?> cls4 = getClass();
                decodeStream2 = BitmapFactory.decodeStream(cls4.getResourceAsStream("/com/esri/android/map/res/Magnifier@2x.png"), null, options);
            }
            MapSurface mapSurface = this.a;
            if (mapSurface != null && decodeStream != null && decodeStream2 != null) {
                mapSurface.a(decodeStream, decodeStream2);
            } else {
                Log.e(com.esri.core.internal.a.a, "fail to initialize Map magnifier.");
            }
        } catch (Exception unused) {
            Log.e(com.esri.core.internal.a.a, "fail to initialize Map magnifier.");
        }
    }

    public void a(float f, float f2) {
        MapSurface mapSurface = this.a;
        if (mapSurface != null) {
            mapSurface.b(f, f2);
        }
    }

    public void c() {
        MapSurface mapSurface = this.a;
        if (mapSurface != null) {
            mapSurface.c(false);
        }
    }

    public void a(boolean z) {
        MapSurface mapSurface = this.a;
        if (mapSurface != null) {
            mapSurface.d(z);
        }
    }

    public boolean setMapOptions(MapOptions mapOptions) {
        Layer[] layers;
        if (!isLoaded() || mapOptions == null || mapOptions.a == null || getSpatialReference().getID() != SpatialReference.WKID_WGS84_WEB_MERCATOR_AUXILIARY_SPHERE) {
            return false;
        }
        this.o = mapOptions;
        for (Layer layer : getLayers()) {
            if (layer.isWebMapBaselayer()) {
                removeLayer(layer);
            }
        }
        d();
        return true;
    }

    public void setMaxScale(double d) {
        MapSurface mapSurface = this.a;
        if (mapSurface == null || d <= Utils.DOUBLE_EPSILON) {
            return;
        }
        mapSurface.d(d);
    }

    public double getMaxScale() {
        MapSurface mapSurface = this.a;
        return mapSurface != null ? mapSurface.t() : Utils.DOUBLE_EPSILON;
    }

    public void setMinScale(double d) {
        MapSurface mapSurface = this.a;
        if (mapSurface == null || d <= Utils.DOUBLE_EPSILON) {
            return;
        }
        mapSurface.e(d);
    }

    public double getMinScale() {
        MapSurface mapSurface = this.a;
        return mapSurface != null ? mapSurface.u() : Utils.DOUBLE_EPSILON;
    }

    private UserCredentials a(String str, String str2) {
        if (com.esri.core.internal.util.a.a(str)) {
            return null;
        }
        UserCredentials userCredentials = new UserCredentials();
        userCredentials.setUserAccount(str, str2);
        return userCredentials;
    }

    private void j() {
        LocationDisplayManager locationDisplayManager = this.i;
        if (locationDisplayManager == null || !locationDisplayManager.isStarted() || this.i.getAutoPanMode() == LocationDisplayManager.AutoPanMode.OFF) {
            return;
        }
        this.i.setAutoPanMode(LocationDisplayManager.AutoPanMode.OFF);
    }

    public Future<Boolean> switchBaseMap(final BaseMap baseMap, final Portal portal, final OnBaseMapSwitchListener onBaseMapSwitchListener) {
        if (!isLoaded()) {
            throw new IllegalStateException(I);
        }
        Future<Boolean> future = this.G;
        if (future != null) {
            future.cancel(true);
        }
        Future<Boolean> submit = e.b.submit(new Callable<Boolean>() { // from class: com.esri.android.map.MapView.8
            {
                MapView.this = this;
            }

            @Override // java.util.concurrent.Callable
            /* renamed from: a */
            public Boolean call() throws Exception {
                Boolean bool = Boolean.FALSE;
                try {
                    if (Thread.currentThread().isInterrupted()) {
                        throw new InterruptedException();
                    }
                    BaseMap baseMap2 = baseMap;
                    if (baseMap2 != null && baseMap2.getBaseMapLayers() != null && !baseMap.getBaseMapLayers().isEmpty()) {
                        b bVar = new b(null, MapView.this, portal, false, onBaseMapSwitchListener);
                        ArrayList arrayList = new ArrayList();
                        ArrayList arrayList2 = new ArrayList();
                        for (WebMapLayer webMapLayer : baseMap.getBaseMapLayers()) {
                            if (webMapLayer.isReference()) {
                                arrayList2.add(webMapLayer);
                            } else {
                                arrayList.add(webMapLayer);
                            }
                        }
                        final List<Layer> a2 = bVar.a(arrayList);
                        if (!a2.isEmpty()) {
                            Layer layer = a2.get(0);
                            layer.waitForInitialized();
                            SpatialReference defaultSpatialReference = layer.getDefaultSpatialReference();
                            SpatialReference spatialReference = MapView.this.getSpatialReference();
                            if (defaultSpatialReference == null || !defaultSpatialReference.equals(spatialReference)) {
                                layer.n = MapView.this.s;
                                OnStatusChangedListener.EsriStatusException esriStatusException = new OnStatusChangedListener.EsriStatusException(OnStatusChangedListener.EsriStatusException.SPATIAL_REFERENCE_INVALID);
                                layer.changeStatus(OnStatusChangedListener.STATUS.fromInt(OnStatusChangedListener.STATUS.LAYER_LOADING_FAILED.getValue(), esriStatusException));
                                OnBaseMapSwitchListener onBaseMapSwitchListener2 = onBaseMapSwitchListener;
                                if (onBaseMapSwitchListener2 != null) {
                                    onBaseMapSwitchListener2.onBaseMapSwitchCompleted(baseMap, esriStatusException);
                                }
                                return Boolean.FALSE;
                            }
                        }
                        final List<Layer> a3 = bVar.a(arrayList2);
                        if (Thread.currentThread().isInterrupted()) {
                            throw new InterruptedException();
                        }
                        MapView.this.s.post(new Runnable() { // from class: com.esri.android.map.MapView.8.1
                            {
                                AnonymousClass8.this = this;
                            }

                            @Override // java.lang.Runnable
                            public void run() {
                                Layer[] layers = MapView.this.getLayers();
                                if (layers != null) {
                                    for (Layer layer2 : layers) {
                                        if (layer2.isWebMapBaselayer()) {
                                            MapView.this.removeLayer(layer2);
                                        }
                                    }
                                }
                                for (int size = a2.size() - 1; size >= 0; size--) {
                                    Layer layer3 = (Layer) a2.get(size);
                                    MapView.this.addLayer(layer3, 0);
                                    layer3.a(true);
                                }
                                for (Layer layer4 : a3) {
                                    MapView.this.addLayer(layer4);
                                    layer4.a(true);
                                }
                                if (onBaseMapSwitchListener != null) {
                                    onBaseMapSwitchListener.onBaseMapSwitchCompleted(baseMap, null);
                                }
                            }
                        });
                        return Boolean.TRUE;
                    }
                    return Boolean.FALSE;
                } catch (Exception e) {
                    OnBaseMapSwitchListener onBaseMapSwitchListener3 = onBaseMapSwitchListener;
                    if (onBaseMapSwitchListener3 != null) {
                        onBaseMapSwitchListener3.onBaseMapSwitchCompleted(baseMap, e);
                    }
                    throw e;
                }
            }
        });
        this.G = submit;
        return submit;
    }
}
